Update setting of buildin internal types
authorMarek Safar <marek.safar@gmail.com>
Thu, 2 Dec 2010 11:25:48 +0000 (11:25 +0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 2 Dec 2010 12:10:27 +0000 (12:10 +0000)
mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs
mcs/mcs/driver.cs
mcs/mcs/eval.cs
mcs/mcs/typemanager.cs
mcs/mcs/typespec.cs

index 7ede541071aeab35231d34d9842c6fe759f98887..681e50f8a93c7a67b3c322c5021e084e9a7eee5f 100644 (file)
@@ -201,7 +201,7 @@ namespace Microsoft.CSharp.RuntimeBinder
                                }
 
                                if (!Compiler.RootContext.EvalMode) {
-                                       Compiler.TypeManager.InitCoreTypes (module, cc.BuildinTypes);
+                                       cc.BuildinTypes.CheckDefinitions (module);
                                        module.InitializePredefinedTypes ();
                                }
 
index 154c41676aaf405c39e8392ed78a1ea4a0e1f977..6f8fdf0888f348991c1a74369ab1e98bc63e23f6 100644 (file)
@@ -1450,7 +1450,7 @@ namespace Mono.CSharp
 
                        ShowTime ("Imporing referenced assemblies");
 
-                       if (!TypeManager.InitCoreTypes (module, ctx.BuildinTypes))
+                       if (!ctx.BuildinTypes.CheckDefinitions (module))
                                return false;
 
                        ShowTime ("Initializing predefined types");
index 48952b8187a007560c6146f48542e2091dbbd18d..2327409e6f24495ac2322cce1bd14ac8352ce08b 100644 (file)
@@ -132,7 +132,7 @@ namespace Mono.CSharp {
 
                                RootContext.ToplevelTypes.MakeExecutable ("temp");
                                loader.LoadReferences (RootContext.ToplevelTypes);
-                               TypeManager.InitCoreTypes (RootContext.ToplevelTypes, ctx.BuildinTypes);
+                               ctx.BuildinTypes.CheckDefinitions (RootContext.ToplevelTypes);
                                RootContext.ToplevelTypes.InitializePredefinedTypes ();
 
                                RootContext.EvalMode = true;
index 5c029c6eba2d0351d6b49c3891988524dcc291e9..1f28fb0c1e3ab7fc71e98f602ed849c1f9668633 100644 (file)
@@ -57,6 +57,13 @@ namespace Mono.CSharp
                public readonly BuildinTypeSpec RuntimeTypeHandle;
                public readonly BuildinTypeSpec Exception;
 
+               //
+               // These are internal buil-in types which depend on other
+               // build-in type (mostly object)
+               //
+               public readonly BuildinTypeSpec Dynamic;
+               public readonly BuildinTypeSpec Null;
+
                readonly BuildinTypeSpec[] types;
 
                public BuildinTypes ()
@@ -97,6 +104,10 @@ namespace Mono.CSharp
                        RuntimeFieldHandle = new BuildinTypeSpec (MemberKind.Struct, "System", "RuntimeFieldHandle", BuildinTypeSpec.Type.RuntimeFieldHandle);
                        RuntimeTypeHandle = new BuildinTypeSpec (MemberKind.Struct, "System", "RuntimeTypeHandle", BuildinTypeSpec.Type.RuntimeTypeHandle);
 
+                       Dynamic = new BuildinTypeSpec ("dynamic", BuildinTypeSpec.Type.Dynamic);
+                       Null = new BuildinTypeSpec ("null", BuildinTypeSpec.Type.Null);
+                       Null.MemberCache = MemberCache.Empty;
+
                        types = new BuildinTypeSpec[] {
                                Object, ValueType, Attribute,
                                Int, UInt, Long, ULong, Float, Double, Char, Short, Decimal, Bool, SByte, Byte, UShort, String,
@@ -136,17 +147,38 @@ namespace Mono.CSharp
                        TypeManager.runtime_field_handle_type = RuntimeFieldHandle;
                        TypeManager.attribute_type = Attribute;
                        TypeManager.exception_type = Exception;
-               }
 
-               #region Properties
+                       InternalType.Dynamic = Dynamic;
+                       InternalType.Null = Null;
+               }
 
-               public BuildinTypeSpec[] Types {
-                       get {
-                               return types;
+               public bool CheckDefinitions (ModuleContainer module)
+               {
+                       var ctx = module.Compiler;
+                       foreach (var p in types) {
+                               var found = PredefinedType.Resolve (module, p.Kind, p.Namespace, p.Name, p.Arity, Location.Null);
+                               if (found == null || found == p)
+                                       continue;
+
+                               if (!RootContext.StdLib) {
+                                       var ns = module.GlobalRootNamespace.GetNamespace (p.Namespace, false);
+                                       ns.ReplaceTypeWithPredefined (found, p);
+
+                                       var tc = found.MemberDefinition as TypeContainer;
+                                       tc.SetPredefinedSpec (p);
+                                       p.SetDefinition (found);
+                               }
                        }
-               }
 
-               #endregion
+                       if (ctx.Report.Errors != 0)
+                               return false;
+
+                       // Set internal build-in types
+                       Dynamic.SetDefinition (Object);
+                       Null.SetDefinition (Object);
+
+                       return true;
+               }
        }
 
        //
@@ -578,41 +610,6 @@ namespace Mono.CSharp
                return GetPredefinedMember (t, MemberFilter.Property (name, type), false, loc) as PropertySpec;
        }
 
-       /// <remarks>
-       ///   The types have to be initialized after the initial
-       ///   population of the type has happened (for example, to
-       ///   bootstrap the corlib.dll
-       /// </remarks>
-       public static bool InitCoreTypes (ModuleContainer module, BuildinTypes buildin)
-       {
-               var ctx = module.Compiler;
-               foreach (var p in buildin.Types) {
-                       var found = PredefinedType.Resolve (module, p.Kind, p.Namespace, p.Name, p.Arity, Location.Null);
-                       if (found == null || found == p)
-                               continue;
-
-                       if (!RootContext.StdLib) {
-                               var ns = module.GlobalRootNamespace.GetNamespace (p.Namespace, false);
-                               ns.ReplaceTypeWithPredefined (found, p);
-
-                               var tc = found.MemberDefinition as TypeContainer;
-                               tc.SetPredefinedSpec (p);
-                               p.SetDefinition (found);
-                       }
-               }
-
-               if (InternalType.Dynamic.GetMetaInfo () == null) {
-                       InternalType.Dynamic.SetMetaInfo (object_type.GetMetaInfo ());
-
-                       if (object_type.MemberDefinition.IsImported)
-                               InternalType.Dynamic.MemberCache = object_type.MemberCache;
-
-                       InternalType.Null.SetMetaInfo (object_type.GetMetaInfo ());
-               }
-
-               return ctx.Report.Errors == 0;
-       }
-
        public static bool IsBuiltinType (TypeSpec t)
        {
                if (t == object_type || t == string_type || t == int32_type || t == uint32_type ||
index d9c36f32fa1d0f01eb9d9770e4d5feb4eb611872..f04223cec9e57aa9dc54612a9f4618478aafcceb 100644 (file)
@@ -471,7 +471,10 @@ namespace Mono.CSharp
                        UIntPtr,
                        RuntimeFieldHandle,
                        RuntimeTypeHandle,
-                       Exception
+                       Exception,
+
+                       Null,
+                       Dynamic
                }
 
                readonly Type type;
@@ -489,6 +492,13 @@ namespace Mono.CSharp
                        this.name = name;
                }
 
+               public BuildinTypeSpec (string name, Type buildinKind)
+                       : this (MemberKind.InternalCompilerType, "", name, buildinKind)
+               {
+                       // Make all internal types CLS-compliant, non-obsolete
+                       state = (state & ~(StateFlags.CLSCompliant_Undetected | StateFlags.Obsolete_Undetected)) | StateFlags.CLSCompliant;
+               }
+
                #region Properties
 
                public override int Arity {
@@ -538,6 +548,9 @@ namespace Mono.CSharp
                        case "SByte": return "sbyte";
                        }
 
+                       if (ns.Length == 0)
+                               return name;
+
                        return ns + "." + name;
                }
 
@@ -940,9 +953,9 @@ namespace Mono.CSharp
        {
                public static readonly InternalType AnonymousMethod = new InternalType ("anonymous method");
                public static readonly InternalType Arglist = new InternalType ("__arglist");
-               public static readonly InternalType Dynamic = new InternalType ("dynamic", null);
+               public static BuildinTypeSpec Dynamic;
                public static readonly InternalType MethodGroup = new InternalType ("method group");
-               public static readonly InternalType Null = new InternalType ("null");
+               public static BuildinTypeSpec Null;
                public static readonly InternalType FakeInternalType = new InternalType ("<fake$type>");
 
                readonly string name;