From: Marek Safar Date: Thu, 2 Dec 2010 11:25:48 +0000 (+0000) Subject: Update setting of buildin internal types X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=89d372ff9faeeb14c1dae0feba689854190e7bac;p=mono.git Update setting of buildin internal types --- diff --git a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs index 7ede541071a..681e50f8a93 100644 --- a/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs +++ b/mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs @@ -201,7 +201,7 @@ namespace Microsoft.CSharp.RuntimeBinder } if (!Compiler.RootContext.EvalMode) { - Compiler.TypeManager.InitCoreTypes (module, cc.BuildinTypes); + cc.BuildinTypes.CheckDefinitions (module); module.InitializePredefinedTypes (); } diff --git a/mcs/mcs/driver.cs b/mcs/mcs/driver.cs index 154c41676aa..6f8fdf0888f 100644 --- a/mcs/mcs/driver.cs +++ b/mcs/mcs/driver.cs @@ -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"); diff --git a/mcs/mcs/eval.cs b/mcs/mcs/eval.cs index 48952b8187a..2327409e6f2 100644 --- a/mcs/mcs/eval.cs +++ b/mcs/mcs/eval.cs @@ -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; diff --git a/mcs/mcs/typemanager.cs b/mcs/mcs/typemanager.cs index 5c029c6eba2..1f28fb0c1e3 100644 --- a/mcs/mcs/typemanager.cs +++ b/mcs/mcs/typemanager.cs @@ -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; } - /// - /// The types have to be initialized after the initial - /// population of the type has happened (for example, to - /// bootstrap the corlib.dll - /// - 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 || diff --git a/mcs/mcs/typespec.cs b/mcs/mcs/typespec.cs index d9c36f32fa1..f04223cec9e 100644 --- a/mcs/mcs/typespec.cs +++ b/mcs/mcs/typespec.cs @@ -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 (""); readonly string name;