**** Merged r36954 from MCS ****
[mono.git] / mcs / gmcs / rootcontext.cs
index ff528c9052e6a82388de71d44e635c7b39fc4d1d..f792d213ac618eb576c6d5b51dd6f55ae10a29a2 100755 (executable)
@@ -7,15 +7,23 @@
 // Licensed under the terms of the GNU GPL
 //
 // (C) 2001 Ximian, Inc (http://www.ximian.com)
+// (C) 2004 Novell, Inc
 
 using System;
 using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Diagnostics;
+using System.Xml;
 
 namespace Mono.CSharp {
 
+       public enum LanguageVersion
+       {
+               Default = 0,
+               ISO_1   = 1
+       }
+
        public class RootContext {
 
                //
@@ -46,7 +54,6 @@ namespace Mono.CSharp {
                // override).
                //
                static ArrayList type_container_resolve_order;
-               static ArrayList interface_resolve_order;
                static ArrayList attribute_types;
 
                //
@@ -64,10 +71,7 @@ namespace Mono.CSharp {
 
                public static bool VerifyClsCompliance = true;
 
-               //
-               // If set, enable C# version 2 features
-               //
-               public static bool V2 = true;
+               public static LanguageVersion Version = LanguageVersion.Default;
 
                //
                // We keep strongname related info here because
@@ -77,13 +81,17 @@ namespace Mono.CSharp {
                public static string StrongNameKeyContainer;
                public static bool StrongNameDelaySign = false;
 
+               //
+               // If set, enable XML documentation generation
+               //
+               public static Documentation Documentation;
+
                //
                // Constructor
                //
                static RootContext ()
                {
                        tree = new Tree ();
-                       interface_resolve_order = new ArrayList ();
                        type_container_resolve_order = new ArrayList ();
                }
 
@@ -101,11 +109,6 @@ namespace Mono.CSharp {
 
                static public string MainClass;
                
-               public static void RegisterOrder (Interface iface)
-               {
-                       interface_resolve_order.Add (iface);
-               }
-               
                public static void RegisterOrder (TypeContainer tc)
                {
                        type_container_resolve_order.Add (tc);
@@ -308,9 +311,16 @@ namespace Mono.CSharp {
                                "System.IDisposable",
                                
                                "System.Runtime.Serialization.ISerializable",
+                               "System.Runtime.InteropServices._Exception",
 
                                "System.Reflection.IReflect",
-                               "System.Reflection.ICustomAttributeProvider"
+                               "System.Reflection.ICustomAttributeProvider",
+
+                               //
+                               // Generic types
+                               //
+                               "System.Collections.Generic.IEnumerator`1",
+                               "System.Collections.Generic.IEnumerable`1"
                        };
 
                        foreach (string iname in interfaces_first_stage)
@@ -340,6 +350,7 @@ namespace Mono.CSharp {
                                "System.Char",    "System.Boolean",
                                "System.Decimal", "System.Void",
                                "System.RuntimeFieldHandle",
+                               "System.RuntimeArgumentHandle",
                                "System.RuntimeTypeHandle",
                                "System.IntPtr",
                                "System.TypedReference",
@@ -376,12 +387,16 @@ namespace Mono.CSharp {
                                "System.ParamArrayAttribute",
                                "System.CLSCompliantAttribute",
                                "System.Security.UnverifiableCodeAttribute",
+                               "System.Security.Permissions.SecurityAttribute",
                                "System.Runtime.CompilerServices.IndexerNameAttribute",
+                               "System.Runtime.CompilerServices.DecimalConstantAttribute",
                                "System.Runtime.InteropServices.InAttribute",
                                "System.Runtime.InteropServices.StructLayoutAttribute",
                                "System.Runtime.InteropServices.FieldOffsetAttribute",
                                "System.InvalidOperationException",
-                               "System.MarshalByRefObject"
+                               "System.NotSupportedException",
+                               "System.MarshalByRefObject",
+                               "System.Security.CodeAccessPermission"
                        };
 
                        // We must store them here before calling BootstrapCorlib_ResolveDelegate.
@@ -419,9 +434,6 @@ namespace Mono.CSharp {
                                foreach (TypeContainer tc in attribute_types)
                                        tc.CloseType ();
                        
-                       foreach (Interface iface in interface_resolve_order)
-                               iface.CloseType ();
-
                        //
                        // We do this in two passes, first we close the structs,
                        // then the classes, because it seems the code needs it this
@@ -429,13 +441,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 is Struct && tc.Parent == tree.Types){
+                               if (tc.Kind == Kind.Struct && tc.Parent == tree.Types){
                                        tc.CloseType ();
                                }
                        }
 
                        foreach (TypeContainer tc in type_container_resolve_order){
-                               if (!(tc is Struct && tc.Parent == tree.Types))
+                               if (!(tc.Kind == Kind.Struct && tc.Parent == tree.Types))
                                        tc.CloseType ();                                        
                        }
                        
@@ -453,10 +465,9 @@ namespace Mono.CSharp {
                        }
                        
                        attribute_types = null;
-                       interface_resolve_order = null;
                        type_container_resolve_order = null;
                        helper_classes = null;
-                       tree = null;
+                       //tree = null;
                        TypeManager.CleanUp ();
                }
 
@@ -486,14 +497,13 @@ namespace Mono.CSharp {
                        return ns.Substring (0, i);
                }
 
-               static TypeExpr NamespaceLookup (DeclSpace ds, string name,
-                                                int num_type_args, bool silent, Location loc)
+               static Type 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) {
-                               IAlias result = ns.Lookup (ds, name, num_type_args, silent, loc);
+                               IAlias result = ns.Lookup (ds, name, num_type_args, false, loc);
 
                                if (result == null)
                                        continue;
@@ -501,14 +511,17 @@ namespace Mono.CSharp {
                                if (!result.IsType)
                                        return null;
 
-                               return result.Type;
+                               TypeExpr texpr = result.ResolveAsType (ds.EmitContext);
+                               if (texpr == null)
+                                       return null;
+
+                               return texpr.Type;
                        }
 
                        return null;
                }
                
-               static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
-                                                  Location loc)
+               static public Type LookupType (DeclSpace ds, string name, bool silent, Location loc)
                {
                        return LookupType (ds, name, silent, 0, loc);
                }
@@ -521,13 +534,13 @@ namespace Mono.CSharp {
                //
                // Come to think of it, this should be a DeclSpace
                //
-               static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
-                                                  int num_type_params, Location loc)
+               static public Type LookupType (DeclSpace ds, string name, bool silent,
+                                              int num_type_params, Location loc)
                {
-                       TypeExpr t;
+                       Type t;
 
                        if (ds.Cache.Contains (name)){
-                               t = (TypeExpr) ds.Cache [name];
+                               t = (Type) ds.Cache [name];
                                if (t != null)
                                        return t;
                        } else {
@@ -545,7 +558,7 @@ namespace Mono.CSharp {
                                                //
                                                Type type = TypeManager.LookupType (current_type.FullName + "." + name);
                                                if (type != null){
-                                                       t = new TypeExpression (type, loc);
+                                                       t = ds.ResolveNestedType (type, loc);
                                                        ds.Cache [name] = t;
                                                        return t;
                                                }
@@ -556,8 +569,8 @@ namespace Mono.CSharp {
                                        containing_ds = containing_ds.Parent;
                                }
                                
-                               t = NamespaceLookup (ds, name, num_type_params, silent, loc);
-                               if (t != null){
+                               t = NamespaceLookup (ds, name, num_type_params, loc);
+                               if (!silent || t != null){
                                        ds.Cache [name] = t;
                                        return t;
                                }
@@ -573,25 +586,11 @@ namespace Mono.CSharp {
                //   This is the silent version of LookupType, you can use this
                //   to `probe' for a type
                // </summary>
-               static public TypeExpr LookupType (TypeContainer tc, string name, Location loc)
+               static public Type LookupType (TypeContainer tc, string name, Location loc)
                {
                        return LookupType (tc, name, true, loc);
                }
 
-               static public bool IsNamespace (string name)
-               {
-                       Namespace ns;
-
-                       if (tree.Namespaces != null){
-                               ns = (Namespace) tree.Namespaces [name];
-
-                               if (ns != null)
-                                       return true;
-                       }
-
-                       return false;
-               }
-
                static void Report1530 (Location loc)
                {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
@@ -602,7 +601,7 @@ namespace Mono.CSharp {
                        DeclSpace ds = (DeclSpace) root.GetDefinition (name);
 
                        ds.DefineMembers (root);
-                       ds.Define (root);
+                       ds.Define ();
                }
                
                static public void BootCorlib_PopulateCoreTypes ()
@@ -627,15 +626,6 @@ namespace Mono.CSharp {
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
                                        tc.DefineMembers (root);
-                       
-                       if (interface_resolve_order != null){
-                               foreach (Interface iface in interface_resolve_order)
-                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.DefineMembers (root);
-                                       else
-                                               Report1530 (iface.Location);
-                       }
-
 
                        if (type_container_resolve_order != null){
                                if (RootContext.StdLib){
@@ -702,14 +692,7 @@ namespace Mono.CSharp {
 
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
-                                       tc.Define (root);
-                       
-                       if (interface_resolve_order != null){
-                               foreach (Interface iface in interface_resolve_order)
-                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.Define (root);
-                       }
-
+                                       tc.Define ();
 
                        if (type_container_resolve_order != null){
                                foreach (TypeContainer tc in type_container_resolve_order) {
@@ -722,7 +705,7 @@ namespace Mono.CSharp {
                                                continue;
 
                                        if ((tc.ModFlags & Modifiers.NEW) == 0)
-                                               tc.Define (root);
+                                               tc.Define ();
                                }
                        }
 
@@ -730,14 +713,14 @@ namespace Mono.CSharp {
                        if (delegates != null){
                                foreach (Delegate d in delegates)
                                        if ((d.ModFlags & Modifiers.NEW) == 0)
-                                               d.Define (root);
+                                               d.Define ();
                        }
 
                        ArrayList enums = root.Enums;
                        if (enums != null){
                                foreach (Enum en in enums)
                                        if ((en.ModFlags & Modifiers.NEW) == 0)
-                                               en.Define (root);
+                                               en.Define ();
                        }
                }
 
@@ -745,32 +728,24 @@ namespace Mono.CSharp {
                {
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
-                                       tc.Emit ();
+                                       tc.EmitType ();
 
                        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);
+                                       e.Emit ();
                        }
 
-                        if (interface_resolve_order != null){
-                               foreach (Interface iface in interface_resolve_order)
-                                       iface.Emit (Tree.Types);
-                       }                        
-                       
                        if (type_container_resolve_order != null) {
                                foreach (TypeContainer tc in type_container_resolve_order)
-                                       tc.EmitConstants ();
-                               
-                               foreach (TypeContainer tc in type_container_resolve_order)
-                                       tc.Emit ();
+                                       tc.EmitType ();
                        }
                        
                        if (Tree.Types.Delegates != null) {
                                foreach (Delegate d in Tree.Types.Delegates)
-                                       d.Emit (Tree.Types);
+                                       d.Emit ();
                        }                       
                        //
                        // Run any hooks after all the types have been defined.