X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Frootcontext.cs;h=4c6335c0b79ab42689d99ed9f78a9572a51b8c8a;hb=d61eb6ded629db1bc89fc53df1ab2affc4a0b767;hp=f12d05e6c5b6e9d8952572c8bb789081a2a9233c;hpb=b254c9e9e90e6792929a19ec93d0464ce451e2a6;p=mono.git diff --git a/mcs/mcs/rootcontext.cs b/mcs/mcs/rootcontext.cs index f12d05e6c5b..4c6335c0b79 100644 --- a/mcs/mcs/rootcontext.cs +++ b/mcs/mcs/rootcontext.cs @@ -12,7 +12,7 @@ // Copyright 2004-2008 Novell, Inc using System; -using System.Collections; +using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; using System.Diagnostics; @@ -22,16 +22,19 @@ namespace Mono.CSharp { public enum LanguageVersion { ISO_1 = 1, - Default_MCS = 2, - ISO_2 = 3, - LINQ = 4, - Future = 5, + ISO_2 = 2, + V_3 = 3, + V_4 = 4, + Future = 100, -#if GMCS_SOURCE - Default = LINQ -#else - Default = Default_MCS -#endif + Default = LanguageVersion.V_4, + } + + public enum MetadataVersion + { + v1, + v2, + v4 } public class RootContext { @@ -40,10 +43,14 @@ namespace Mono.CSharp { // COMPILER OPTIONS CLASS // public static Target Target; + public static Platform Platform; public static string TargetExt; public static bool VerifyClsCompliance = true; public static bool Optimize = true; public static LanguageVersion Version; + public static bool EnhancedWarnings; + + public static MetadataVersion MetadataCompatibilityVersion; // // We keep strongname related info here because @@ -102,33 +109,24 @@ namespace Mono.CSharp { // // Contains the parsed tree // - static RootTypes root; + static ModuleCompiled root; // // This hashtable contains all of the #definitions across the source code // it is used by the ConditionalAttribute handler. // - static ArrayList AllDefines = new ArrayList (); + static List AllDefines; - // - // This keeps track of the order in which classes were defined - // so that we can poulate them in that order. - // - // Order is important, because we need to be able to tell, by - // examining the list of methods of the base class, which ones are virtual - // or abstract as well as the parent names (to implement new, - // override). - // - static ArrayList type_container_resolve_order; - // // Holds a reference to the Private Implementation Details // class. // - static ArrayList helper_classes; + static List helper_classes; static TypeBuilder impl_details_class; + public static List hack_corlib_enums = new List (); + // // Constructor // @@ -144,12 +142,13 @@ namespace Mono.CSharp { public static void Reset (bool full) { - if (full) - root = new RootTypes (); + impl_details_class = null; + helper_classes = null; + + if (!full) + return; - type_container_resolve_order = new ArrayList (); EntryPoint = null; - Report.WarningLevel = 4; Checked = false; Unsafe = false; StdLib = true; @@ -159,16 +158,23 @@ namespace Mono.CSharp { MainClass = null; Target = Target.Exe; TargetExt = ".exe"; + Platform = Platform.AnyCPU; Version = LanguageVersion.Default; Documentation = null; impl_details_class = null; helper_classes = null; +#if NET_4_0 + MetadataCompatibilityVersion = MetadataVersion.v4; +#else + MetadataCompatibilityVersion = MetadataVersion.v2; +#endif + // // Setup default defines // - RootContext.AllDefines = new ArrayList (); - RootContext.AddConditional ("__MonoCS__"); + AllDefines = new List (); + AddConditional ("__MonoCS__"); } public static void AddConditional (string p) @@ -183,15 +189,11 @@ namespace Mono.CSharp { return AllDefines.Contains (value); } - static public RootTypes ToplevelTypes { + static public ModuleCompiled ToplevelTypes { get { return root; } + set { root = value; } } - public static void RegisterOrder (TypeContainer tc) - { - type_container_resolve_order.Add (tc); - } - // // This function is used to resolve the hierarchy tree. // It processes interfaces, structs and classes in that order. @@ -201,6 +203,8 @@ namespace Mono.CSharp { // static public void ResolveTree () { + root.Resolve (); + // // Interfaces are processed next, as classes and // structs might inherit from an object or implement @@ -212,10 +216,44 @@ namespace Mono.CSharp { foreach (TypeContainer tc in root.Types) tc.DefineType (); + } + + static void HackCorlib () + { + if (StdLib) + return; + + // + // HACK: When building corlib mcs uses loaded mscorlib which + // has different predefined types and this method sets mscorlib types + // to be same to avoid type check errors in CreateType. + // + var type = typeof (Type); + var system_4_type_arg = new[] { type, type, type, type }; + + MethodInfo set_corlib_type_builders = + typeof (System.Reflection.Emit.AssemblyBuilder).GetMethod ( + "SetCorlibTypeBuilders", BindingFlags.NonPublic | BindingFlags.Instance, null, + system_4_type_arg, null); - if (root.Delegates != null) - foreach (Delegate d in root.Delegates) - d.DefineType (); + if (set_corlib_type_builders == null) { + root.Compiler.Report.Warning (-26, 3, "The compilation may fail due to missing `{0}.SetCorlibTypeBuilders(...)' method", + typeof (System.Reflection.Emit.AssemblyBuilder).FullName); + return; + } + + object[] args = new object[4]; + args[0] = TypeManager.object_type.GetMetaInfo (); + args[1] = TypeManager.value_type.GetMetaInfo (); + args[2] = TypeManager.enum_type.GetMetaInfo (); + args[3] = TypeManager.void_type.GetMetaInfo (); + set_corlib_type_builders.Invoke (CodeGen.Assembly.Builder, args); + + // Another Mono corlib HACK + // mono_class_layout_fields requires to have enums created + // before creating a class which used the enum for any of its fields + foreach (var e in hack_corlib_enums) + e.CloseType (); } // @@ -230,44 +268,27 @@ namespace Mono.CSharp { // static public void CloseTypes () { - // - // We do this in two passes, first we close the structs, - // then the classes, because it seems the code needs it this - // way. If this is really what is going on, we should probably - // make sure that we define the structs in order as well. - // - foreach (TypeContainer tc in type_container_resolve_order){ - if (tc.Kind == Kind.Struct && tc.Parent == root){ - tc.CloseType (); - } - } + HackCorlib (); - foreach (TypeContainer tc in type_container_resolve_order){ - if (!(tc.Kind == Kind.Struct && tc.Parent == root)) - tc.CloseType (); + foreach (TypeContainer tc in root.Types){ + tc.CloseType (); } - - if (root.Delegates != null) - foreach (Delegate d in root.Delegates) - d.CloseType (); + if (root.CompilerGeneratedClasses != null) + foreach (CompilerGeneratedClass c in root.CompilerGeneratedClasses) + c.CloseType (); // // If we have a class, close it // if (helper_classes != null){ foreach (TypeBuilder type_builder in helper_classes) { -#if GMCS_SOURCE - type_builder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location.Null)); -#endif + PredefinedAttributes.Get.CompilerGenerated.EmitAttribute (type_builder); type_builder.CreateType (); } } - type_container_resolve_order = null; helper_classes = null; - //root = null; - TypeManager.CleanUp (); } /// @@ -277,29 +298,11 @@ namespace Mono.CSharp { public static void RegisterCompilerGeneratedType (TypeBuilder helper_class) { if (helper_classes == null) - helper_classes = new ArrayList (); + helper_classes = new List (); helper_classes.Add (helper_class); } - static public void PopulateCoreType (TypeContainer root, string name) - { - DeclSpace ds = (DeclSpace) root.GetDefinition (name); - // Core type was imported - if (ds == null) - return; - - ds.Define (); - } - - static public void BootCorlib_PopulateCoreTypes () - { - PopulateCoreType (root, "System.Object"); - PopulateCoreType (root, "System.ValueType"); - PopulateCoreType (root, "System.Attribute"); - PopulateCoreType (root, "System.Runtime.CompilerServices.IndexerNameAttribute"); - } - // // Populates the structs and classes with fields and methods // @@ -308,50 +311,38 @@ namespace Mono.CSharp { // have been defined through `ResolveTree' static public void PopulateTypes () { + foreach (TypeContainer tc in ToplevelTypes.Types) + tc.ResolveTypeParameters (); - if (type_container_resolve_order != null){ - foreach (TypeContainer tc in type_container_resolve_order) - tc.ResolveType (); - foreach (TypeContainer tc in type_container_resolve_order) + foreach (TypeContainer tc in ToplevelTypes.Types) { + try { tc.Define (); - } - - ArrayList delegates = root.Delegates; - if (delegates != null){ - foreach (Delegate d in delegates) - d.Define (); - } - - // - // 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); + } catch (Exception e) { + throw new InternalErrorException (tc, e); + } } } static public void EmitCode () { - if (type_container_resolve_order != null) { - foreach (TypeContainer tc in type_container_resolve_order) - tc.EmitType (); + foreach (var tc in ToplevelTypes.Types) + tc.DefineConstants (); - if (Report.Errors > 0) - return; + foreach (TypeContainer tc in ToplevelTypes.Types) + tc.EmitType (); - foreach (TypeContainer tc in type_container_resolve_order) - tc.VerifyMembers (); - } - - if (root.Delegates != null) { - foreach (Delegate d in root.Delegates) - d.Emit (); - } + if (ToplevelTypes.Compiler.Report.Errors > 0) + return; + + foreach (TypeContainer tc in ToplevelTypes.Types) + tc.VerifyMembers (); + + if (root.CompilerGeneratedClasses != null) + foreach (CompilerGeneratedClass c in root.CompilerGeneratedClasses) + c.EmitType (); CodeGen.Assembly.Emit (root); - CodeGen.Module.Emit (root); + root.Emit (); } // @@ -384,10 +375,10 @@ namespace Mono.CSharp { FieldBuilder fb; if (impl_details_class == null){ - impl_details_class = CodeGen.Module.Builder.DefineType ( + impl_details_class = ToplevelTypes.Builder.DefineType ( "", TypeAttributes.NotPublic, - TypeManager.object_type); + TypeManager.object_type.GetMetaInfo ()); RegisterCompilerGeneratedType (impl_details_class); } @@ -399,7 +390,7 @@ namespace Mono.CSharp { return fb; } - public static void CheckUnsafeOption (Location loc) + public static void CheckUnsafeOption (Location loc, Report Report) { if (!Unsafe) { Report.Error (227, loc, @@ -408,5 +399,3 @@ namespace Mono.CSharp { } } } - -