**** Merged from MCS ****
[mono.git] / mcs / gmcs / rootcontext.cs
index 74127c6d13770932ad273e1264d9408e150298a8..1428b19099b0a895216603680fb183082776ba10 100755 (executable)
@@ -62,10 +62,21 @@ namespace Mono.CSharp {
                public static Target Target = Target.Exe;
                public static string TargetExt = ".exe";
 
+               public static bool VerifyClsCompliance = true;
+
                //
                // If set, enable C# version 2 features
                //
                public static bool V2 = true;
+
+               //
+               // We keep strongname related info here because
+               // it's also used as complier options from CSC 8.x
+               //
+               public static string StrongNameKeyFile;
+               public static string StrongNameKeyContainer;
+               public static bool StrongNameDelaySign = false;
+
                //
                // Constructor
                //
@@ -262,7 +273,7 @@ namespace Mono.CSharp {
                        object o = root.GetDefinition (name);
                        if (o == null){
                                Report.Error (518, "The predefined type `" + name + "' is not defined");
-                               Environment.Exit (0);
+                               Environment.Exit (1);
                        }
 
                        if (!(o is Delegate)){
@@ -330,7 +341,9 @@ namespace Mono.CSharp {
                                "System.Decimal", "System.Void",
                                "System.RuntimeFieldHandle",
                                "System.RuntimeTypeHandle",
-                               "System.IntPtr"
+                               "System.IntPtr",
+                               "System.TypedReference",
+                               "System.ArgIterator"
                        };
                        
                        foreach (string cname in structs_second_stage)
@@ -343,6 +356,7 @@ namespace Mono.CSharp {
                                "System.Reflection.MemberInfo",
                                "System.Type",
                                "System.Exception",
+                               "System.Activator",
 
                                //
                                // These are not really important in the order, but they
@@ -360,11 +374,14 @@ namespace Mono.CSharp {
                                "System.Diagnostics.ConditionalAttribute",
                                "System.ObsoleteAttribute",
                                "System.ParamArrayAttribute",
+                               "System.CLSCompliantAttribute",
                                "System.Security.UnverifiableCodeAttribute",
                                "System.Runtime.CompilerServices.IndexerNameAttribute",
                                "System.Runtime.InteropServices.InAttribute",
-                               "System.InvalidOperationException"
-
+                               "System.Runtime.InteropServices.StructLayoutAttribute",
+                               "System.Runtime.InteropServices.FieldOffsetAttribute",
+                               "System.InvalidOperationException",
+                               "System.MarshalByRefObject"
                        };
 
                        // We must store them here before calling BootstrapCorlib_ResolveDelegate.
@@ -469,33 +486,29 @@ namespace Mono.CSharp {
                        return ns.Substring (0, i);
                }
 
-               static Type NamespaceLookup (DeclSpace ds, string name,
-                                            int num_type_args, Location loc)
+               static TypeExpr NamespaceLookup (DeclSpace ds, string name,
+                                                int num_type_args, Location loc)
                {
                        //
                        // Try in the current namespace and all its implicit parents
                        //
                        for (NamespaceEntry ns = ds.NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
-                               object result = ns.Lookup (ds, name, loc);
+                               IAlias result = ns.Lookup (ds, name, num_type_args, loc);
+
                                if (result == null)
                                        continue;
 
-                               Type t = result as Type;
-                               if (t != null) {
-                                       if (TypeManager.CheckGeneric (t, num_type_args))
-                                               return t;
-                                       else
-                                               continue;
-                               }
+                               if (!result.IsType)
+                                       return null;
 
-                               return null;
+                               return result.Type;
                        }
 
                        return null;
                }
                
-               static public Type LookupType (DeclSpace ds, string name, bool silent,
-                                              Location loc)
+               static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
+                                                  Location loc)
                {
                        return LookupType (ds, name, silent, 0, loc);
                }
@@ -508,13 +521,13 @@ namespace Mono.CSharp {
                //
                // Come to think of it, this should be a DeclSpace
                //
-               static public Type LookupType (DeclSpace ds, string name, bool silent,
-                                              int num_type_params, Location loc)
+               static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
+                                                  int num_type_params, Location loc)
                {
-                       Type t;
+                       TypeExpr t;
 
                        if (ds.Cache.Contains (name)){
-                               t = (Type) ds.Cache [name];
+                               t = (TypeExpr) ds.Cache [name];
                                if (t != null)
                                        return t;
                        } else {
@@ -530,8 +543,9 @@ namespace Mono.CSharp {
                                                //
                                                // nested class
                                                //
-                                               t = TypeManager.LookupType (current_type.FullName + "." + name);
-                                               if (t != null){
+                                               Type type = TypeManager.LookupType (current_type.FullName + "." + name);
+                                               if (type != null){
+                                                       t = new TypeExpression (type, loc);
                                                        ds.Cache [name] = t;
                                                        return t;
                                                }
@@ -559,7 +573,7 @@ namespace Mono.CSharp {
                //   This is the silent version of LookupType, you can use this
                //   to `probe' for a type
                // </summary>
-               static public Type LookupType (TypeContainer tc, string name, Location loc)
+               static public TypeExpr LookupType (TypeContainer tc, string name, Location loc)
                {
                        return LookupType (tc, name, true, loc);
                }
@@ -658,6 +672,15 @@ namespace Mono.CSharp {
                                        else
                                                Report1530 (en.Location);
                        }
+
+                       //
+                       // Check for cycles in the struct layout
+                       //
+                       if (type_container_resolve_order != null){
+                               Hashtable seen = new Hashtable ();
+                               foreach (TypeContainer tc in type_container_resolve_order)
+                                       TypeManager.CheckStructCycles (tc, seen);
+                       }
                }
 
                //
@@ -720,20 +743,21 @@ namespace Mono.CSharp {
 
                static public void EmitCode ()
                {
-                       //
-                       // Because of the strange way in which we do things, global
-                       // attributes must be processed first.
-                       //
-                       CodeGen.Assembly.Emit ();
-                       CodeGen.Module.Emit ();
-                        
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
                                        tc.Emit ();
 
+                       CodeGen.Assembly.Emit (Tree.Types);
+                       CodeGen.Module.Emit (Tree.Types);
+                        
+                       if (Tree.Types.Enums != null) {
+                               foreach (Enum e in Tree.Types.Enums)
+                                       e.Emit (Tree.Types);
+                       }
+
                         if (interface_resolve_order != null){
                                foreach (Interface iface in interface_resolve_order)
-                                        iface.Emit ();
+                                       iface.Emit (Tree.Types);
                        }                        
                        
                        if (type_container_resolve_order != null) {
@@ -744,6 +768,10 @@ namespace Mono.CSharp {
                                        tc.Emit ();
                        }
                        
+                       if (Tree.Types.Delegates != null) {
+                               foreach (Delegate d in Tree.Types.Delegates)
+                                       d.Emit (Tree.Types);
+                       }                       
                        //
                        // Run any hooks after all the types have been defined.
                        // This is used to create nested auxiliary classes for example