Make all arrays module specific
authorMarek Safar <marek.safar@gmail.com>
Wed, 16 Feb 2011 14:12:42 +0000 (14:12 +0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 16 Feb 2011 14:48:00 +0000 (14:48 +0000)
22 files changed:
mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/DynamicContext.cs
mcs/mcs/anonymous.cs
mcs/mcs/attribute.cs
mcs/mcs/class.cs
mcs/mcs/context.cs
mcs/mcs/doc.cs
mcs/mcs/driver.cs
mcs/mcs/dynamic.cs
mcs/mcs/ecore.cs
mcs/mcs/eval.cs
mcs/mcs/expression.cs
mcs/mcs/generic.cs
mcs/mcs/ikvm.cs
mcs/mcs/import.cs
mcs/mcs/lambda.cs
mcs/mcs/linq.cs
mcs/mcs/method.cs
mcs/mcs/reflection.cs
mcs/mcs/rootcontext.cs
mcs/mcs/roottypes.cs
mcs/mcs/typemanager.cs
mcs/mcs/typespec.cs

index 52b8e1064d650731d517357109ed7536ab9adb9f..98866dee7d61f55f846ea9b16177cbbcb0100179 100644 (file)
@@ -101,7 +101,7 @@ namespace Microsoft.CSharp.RuntimeBinder
                                var domain = AppDomain.CurrentDomain;
 
                                temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
-                               var importer = new Compiler.ReflectionImporter (cc.BuildinTypes) {
+                               var importer = new Compiler.ReflectionImporter (module, cc.BuildinTypes) {
                                        IgnorePrivateMembers = false
                                };
 
index b75d039a74cd17fb7e976c6c68f65a3214d11cbd..bdce5ecfdb14af83a5c52b6f331d3d44127370eb 100644 (file)
@@ -97,7 +97,7 @@ namespace Mono.CSharp {
 
                                // A copy is not enough, inflate any type parameter constraints
                                // using a new type parameters
-                               var inflator = new TypeParameterInflator (null, src, dst);
+                               var inflator = new TypeParameterInflator (this, null, src, dst);
                                for (int i = 0; i < type_params.Length; ++i) {
                                        src[i].InflateConstraints (inflator, dst[i]);
                                }
@@ -211,10 +211,10 @@ namespace Mono.CSharp {
 
                        // Inflated type instance has to be updated manually
                        if (Instance.Type is InflatedTypeSpec) {
-                               var inflator = new TypeParameterInflator (Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+                               var inflator = new TypeParameterInflator (this, Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
                                Instance.Type.MemberCache.AddMember (f.Spec.InflateMember (inflator));
 
-                               inflator = new TypeParameterInflator (f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+                               inflator = new TypeParameterInflator (this, f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
                                f.Parent.CurrentType.MemberCache.AddMember (f.Spec.InflateMember (inflator));
                        }
                }
@@ -1608,7 +1608,7 @@ namespace Mono.CSharp {
                                ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
                        } else {
                                if (delegate_method.IsGeneric)
-                                       delegate_method = delegate_method.MakeGenericMethod (method.TypeParameters);
+                                       delegate_method = delegate_method.MakeGenericMethod (ec.MemberContext, method.TypeParameters);
 
                                ec.Emit (OpCodes.Ldftn, delegate_method);
                        }
index 78165a2ec229712036fbcf4aa335f83788570a3f..7e5cf81cbc322d49df7f8146d0ee01eadb33ec86 100644 (file)
@@ -2017,7 +2017,7 @@ namespace Mono.CSharp {
                        if (Resolve (loc) == null)
                                return false;
 
-                       tctor = TypeManager.GetPredefinedConstructor (type, Location.Null, ArrayContainer.MakeType (TypeManager.bool_type));
+                       tctor = TypeManager.GetPredefinedConstructor (type, Location.Null, ArrayContainer.MakeType (module, TypeManager.bool_type));
                        return tctor != null;
                }
        }
index e79b6eb68268c1fed436028c8537ec1ef9146cdf..ed519850327661fd0f1b80adfbaeeac7b5815b7f 100644 (file)
@@ -253,7 +253,7 @@ namespace Mono.CSharp {
                                                // Switch to inflated version as it's used by all expressions
                                                //
                                                var targs = CurrentTypeParameters == null ? TypeSpec.EmptyTypes : CurrentTypeParameters.Select (l => l.Type).ToArray ();
-                                               current_type = spec.MakeGenericType (targs);
+                                               current_type = spec.MakeGenericType (this, targs);
                                        } else {
                                                current_type = spec;
                                        }
index 0fdb8eb4b8f5e3458e4df34c4b8c79bf25c02c7b..e28101d6e280b861e9a8a4e8a2e485a3fe54eb9c 100644 (file)
@@ -24,7 +24,7 @@ namespace Mono.CSharp
        // Implemented by elements which can act as independent contexts
        // during resolve phase. Used mostly for lookups.
        //
-       public interface IMemberContext
+       public interface IMemberContext : IModuleContext
        {
                //
                // A scope type context, it can be inflated for generic types
@@ -48,7 +48,6 @@ namespace Mono.CSharp
                bool IsUnsafe { get; }
                bool IsStatic { get; }
                bool HasUnresolvedConstraints { get; }
-               ModuleContainer Module { get; }
 
                string GetSignatureForError ();
 
@@ -57,6 +56,11 @@ namespace Mono.CSharp
                FullNamedExpression LookupNamespaceAlias (string name);
        }
 
+       public interface IModuleContext
+       {
+               ModuleContainer Module { get; }
+       }
+
        //
        // Block or statement resolving context
        //
index 2a9b850926702a6f7ccd5cfa40a755cbc8a1a417..7cb6d325be48741858af87bb0d63848306ea5c43 100644 (file)
@@ -264,7 +264,7 @@ namespace Mono.CSharp {
                        }
                        TypeSpec t = FindDocumentedTypeNonArray (mc, identifier, ds, cref, r);
                        if (t != null && is_array)
-                               t = ArrayContainer.MakeType (t);
+                               t = ArrayContainer.MakeType (mc.Module, t);
                        return t;
                }
 
index 3a8d7d8e9cefb434261c87d1c063d50113a32bb7..903e9dd02179f6603f7dad740716f91b23d63c46 100644 (file)
@@ -141,7 +141,7 @@ namespace Mono.CSharp
                        return 1;
                }
 
-               public static string GetPackageFlags (string packages, bool fatal, Report report)
+               public static string GetPackageFlags (string packages, Report report)
                {
                        ProcessStartInfo pi = new ProcessStartInfo ();
                        pi.FileName = "pkg-config";
@@ -152,29 +152,34 @@ namespace Mono.CSharp
                        try {
                                p = Process.Start (pi);
                        } catch (Exception e) {
+                               if (report == null)
+                                       throw;
+
                                report.Error (-27, "Couldn't run pkg-config: " + e.Message);
-                               if (fatal)
-                                       Environment.Exit (1);
-                               p.Close ();
                                return null;
                        }
                        
-                       if (p.StandardOutput == null){
+                       if (p.StandardOutput == null) {
+                               if (report == null)
+                                       throw new ApplicationException ("Specified package did not return any information");
+
                                report.Warning (-27, 1, "Specified package did not return any information");
                                p.Close ();
                                return null;
                        }
+
                        string pkgout = p.StandardOutput.ReadToEnd ();
                        p.WaitForExit ();
                        if (p.ExitCode != 0) {
+                               if (report == null)
+                                       throw new ApplicationException (pkgout);
+
                                report.Error (-27, "Error running pkg-config. Check the above output.");
-                               if (fatal)
-                                       Environment.Exit (1);
                                p.Close ();
                                return null;
                        }
-                       p.Close ();
 
+                       p.Close ();
                        return pkgout;
                }
 
@@ -238,7 +243,7 @@ namespace Mono.CSharp
                        }
 
 #if STATIC
-                       var importer = new StaticImporter ();
+                       var importer = new StaticImporter (module);
                        var references_loader = new StaticLoader (importer, ctx);
 
                        tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
@@ -268,7 +273,7 @@ namespace Mono.CSharp
                        var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
                        module.SetDeclaringAssembly (assembly);
 
-                       var importer = new ReflectionImporter (ctx.BuildinTypes);
+                       var importer = new ReflectionImporter (module, ctx.BuildinTypes);
                        assembly.Importer = importer;
 
                        var loader = new DynamicLoader (importer, ctx);
@@ -390,7 +395,6 @@ namespace Mono.CSharp
 
                        RootContext.Reset (full_flag);
                        TypeManager.Reset ();
-                       ArrayContainer.Reset ();
                        ReferenceContainer.Reset ();
                        PointerContainer.Reset ();
                        Parameter.Reset ();
index fbdfd331c3399d5382c8b9b74a6360221d32131b..1533e543e7b0d4a392647668c8e6cab8a35f3790 100644 (file)
@@ -884,7 +884,7 @@ namespace Mono.CSharp
 
                        // Inflated type instance has to be updated manually
                        if (instance_type is InflatedTypeSpec) {
-                               var inflator = new TypeParameterInflator (instance_type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+                               var inflator = new TypeParameterInflator (this, instance_type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
                                inflated = (TypeSpec) d.CurrentType.InflateMember (inflator);
                                instance_type.MemberCache.AddMember (inflated);
 
@@ -910,7 +910,7 @@ namespace Mono.CSharp
                                //
                                // Inflate the field, no need to keep it in MemberCache as it's accessed only once
                                //
-                               var inflator = new TypeParameterInflator (instance_type, spec.MemberDefinition.TypeParameters, instance_type.TypeArguments);
+                               var inflator = new TypeParameterInflator (this, instance_type, spec.MemberDefinition.TypeParameters, instance_type.TypeArguments);
                                fs = (FieldSpec) fs.InflateMember (inflator);
                        }
 
@@ -921,7 +921,7 @@ namespace Mono.CSharp
                {
                        instance_type = spec;
                        if (mutator != null)
-                               instance_type = instance_type.MakeGenericType (mutator.MethodTypeParameters.Select (l => l.Type).ToArray ());
+                               instance_type = instance_type.MakeGenericType (this, mutator.MethodTypeParameters.Select (l => l.Type).ToArray ());
 
                        return true;
                }
index ce00cf2d4f61db3fedc768fb9115918aa8f86358..2beda2219dc3e8e22c0fbc8b5ef79a526fd7e8bc 100644 (file)
@@ -2636,7 +2636,7 @@ namespace Mono.CSharp {
                                }
 
                                if (targs != null)
-                                       method = method.MakeGenericMethod (targs);
+                                       method = method.MakeGenericMethod (rc, targs);
                        }
 
                        //
@@ -3854,7 +3854,7 @@ namespace Mono.CSharp {
                                        if (g_args_count != type_arguments.Count)
                                                return int.MaxValue - 20000 + System.Math.Abs (type_arguments.Count - g_args_count);
 
-                                       ms = ms.MakeGenericMethod (type_arguments.Arguments);
+                                       ms = ms.MakeGenericMethod (ec, type_arguments.Arguments);
                                } else {
                                        // TODO: It should not be here (we don't know yet whether any argument is lambda) but
                                        // for now it simplifies things. I should probably add a callback to ResolveContext
@@ -3871,7 +3871,7 @@ namespace Mono.CSharp {
                                                return ti.InferenceScore - 20000;
 
                                        if (i_args.Length != 0) {
-                                               ms = ms.MakeGenericMethod (i_args);
+                                               ms = ms.MakeGenericMethod (ec, i_args);
                                        }
 
                                        cc.IgnoreInferredDynamic = true;
@@ -3894,7 +3894,7 @@ namespace Mono.CSharp {
                                //
                                if (candidate != pm) {
                                        MethodSpec override_ms = (MethodSpec) pm;
-                                       var inflator = new TypeParameterInflator (ms.DeclaringType, override_ms.GenericDefinition.TypeParameters, ms.TypeArguments);
+                                       var inflator = new TypeParameterInflator (ec, ms.DeclaringType, override_ms.GenericDefinition.TypeParameters, ms.TypeArguments);
                                        returnType = inflator.Inflate (returnType);
                                } else {
                                        returnType = ms.ReturnType;
index 121e61b1d96deea41a4288594b88723b6698e08d..333cd5a67911c9bdefb0e9fd6e64e6fcfc191938 100644 (file)
@@ -60,12 +60,12 @@ namespace Mono.CSharp
                static Dictionary<string, Tuple<FieldSpec, FieldInfo>> fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
 
                static TypeSpec interactive_base_class;
-               static Driver driver;
                static bool inited;
 
                static CompilerContext ctx;
                static DynamicLoader loader;
                static NamespaceEntry ns;
+               static ModuleContainer module;
                
                public static TextWriter MessageOutput = Console.Out;
 
@@ -141,7 +141,7 @@ namespace Mono.CSharp
                                        IsEvalutor = true
                                };
 
-                               RootContext.ToplevelTypes = new ModuleContainer (ctx);
+                               RootContext.ToplevelTypes = module = new ModuleContainer (ctx);
                                
                                var startup_files = new List<string> ();
                                foreach (CompilationUnit file in Location.SourceFiles)
@@ -149,14 +149,14 @@ namespace Mono.CSharp
                                
                                CompilerCallableEntryPoint.PartialReset ();
 
-                               var importer = new ReflectionImporter (ctx.BuildinTypes);
+                               var importer = new ReflectionImporter (module, ctx.BuildinTypes);
                                loader = new DynamicLoader (importer, ctx);
 
-                               RootContext.ToplevelTypes.SetDeclaringAssembly (new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp"));
+                               module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "temp"));
 
-                               loader.LoadReferences (RootContext.ToplevelTypes);
-                               ctx.BuildinTypes.CheckDefinitions (RootContext.ToplevelTypes);
-                               RootContext.ToplevelTypes.InitializePredefinedTypes ();
+                               loader.LoadReferences (module);
+                               ctx.BuildinTypes.CheckDefinitions (module);
+                               module.InitializePredefinedTypes ();
 
                                inited = true;
 
@@ -268,8 +268,6 @@ namespace Mono.CSharp
                                else
                                        ctx.Report.Printer.Reset ();
 
-                       //      RootContext.ToplevelTypes = new ModuleContainer (ctx);
-
                                bool partial_input;
                                CSharpParser parser = ParseString (ParseMode.Silent, input, out partial_input);
                                if (parser == null){
@@ -414,11 +412,11 @@ namespace Mono.CSharp
                                Class parser_result = parser.InteractiveResult;
 
                                try {
-                                       var a = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp");
+                                       var a = new AssemblyDefinitionDynamic (module, "temp");
                                        a.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run);
-                                       RootContext.ToplevelTypes.SetDeclaringAssembly (a);
-                                       RootContext.ToplevelTypes.CreateType ();
-                                       RootContext.ToplevelTypes.Define ();
+                                       module.SetDeclaringAssembly (a);
+                                       module.CreateType ();
+                                       module.Define ();
 
                                        parser_result.CreateType ();
                                        parser_result.Define ();
@@ -649,9 +647,9 @@ namespace Mono.CSharp
                        seekable.Position = 0;
 
                        if (ns == null)
-                               ns = new NamespaceEntry (RootContext.ToplevelTypes, null, Location.SourceFiles[0], null);
+                               ns = new NamespaceEntry (module, null, Location.SourceFiles[0], null);
 
-                       CSharpParser parser = new CSharpParser (seekable, Location.SourceFiles [0], RootContext.ToplevelTypes, ns);
+                       CSharpParser parser = new CSharpParser (seekable, Location.SourceFiles [0], module, ns);
 
                        if (kind == InputKind.StatementOrExpression){
                                parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
@@ -705,7 +703,7 @@ namespace Mono.CSharp
 
                        if (Environment.GetEnvironmentVariable ("SAVE") != null) {
                                access = AssemblyBuilderAccess.RunAndSave;
-                               assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name, current_debug_name);
+                               assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
                                assembly.Importer = loader.Importer;
                        } else {
 #if NET_4_0
@@ -713,7 +711,7 @@ namespace Mono.CSharp
 #else
                                access = AssemblyBuilderAccess.Run;
 #endif
-                               assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name);
+                               assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
                        }
 
                        assembly.Create (AppDomain.CurrentDomain, access);
@@ -723,8 +721,8 @@ namespace Mono.CSharp
                                host.Define ();
                        }
 
-                       RootContext.ToplevelTypes.CreateType ();
-                       RootContext.ToplevelTypes.Define ();
+                       module.CreateType ();
+                       module.Define ();
 
                        if (Report.Errors != 0){
                                if (undo != null)
@@ -754,14 +752,14 @@ namespace Mono.CSharp
                                host.EmitType ();
                        }
                        
-                       RootContext.ToplevelTypes.Emit ();
+                       module.Emit ();
                        if (Report.Errors != 0){
                                if (undo != null)
                                        undo.ExecuteUndo ();
                                return null;
                        }
 
-                       RootContext.ToplevelTypes.CloseType ();
+                       module.CloseType ();
                        if (host != null)
                                host.CloseType ();
 
@@ -917,7 +915,7 @@ namespace Mono.CSharp
                        lock (evaluator_lock){
                                var a = loader.LoadAssemblyFile (file);
                                if (a != null)
-                                       loader.Importer.ImportAssembly (a, RootContext.ToplevelTypes.GlobalRootNamespace);
+                                       loader.Importer.ImportAssembly (a, module.GlobalRootNamespace);
                        }
                }
 
@@ -927,7 +925,7 @@ namespace Mono.CSharp
                static public void ReferenceAssembly (Assembly a)
                {
                        lock (evaluator_lock){
-                               loader.Importer.ImportAssembly (a, RootContext.ToplevelTypes.GlobalRootNamespace);
+                               loader.Importer.ImportAssembly (a, module.GlobalRootNamespace);
                        }
                }
 
@@ -1035,9 +1033,7 @@ namespace Mono.CSharp
                                return;
                        }
 
-                       string pkgout = Driver.GetPackageFlags (pkg, false, RootContext.ToplevelTypes.Compiler.Report);
-                       if (pkgout == null)
-                               return;
+                       string pkgout = Driver.GetPackageFlags (pkg, null);
 
                        string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
                                Split (new Char [] { ' ', '\t'});
index 0763e84a5a54fc9e46d042a06d71af8d33405e97..23d67b5005c4e3b635d49d38063f32998203deb4 100644 (file)
@@ -5713,7 +5713,7 @@ namespace Mono.CSharp
                                        t, MemberFilter.Method ("CreateInstance", 1, ParametersCompiled.EmptyReadOnlyParameters, null), loc);
                        }
 
-                       var ctor_factory = TypeManager.activator_create_instance.MakeGenericMethod (type);
+                       var ctor_factory = TypeManager.activator_create_instance.MakeGenericMethod (ec.MemberContext, type);
                        var tparam = (TypeParameterSpec) type;
 
                        if (tparam.IsReferenceType) {
@@ -6724,7 +6724,7 @@ namespace Mono.CSharp
                        //
                        UnifyInitializerElement (ec);
 
-                       type = ArrayContainer.MakeType (array_element_type, dimensions);
+                       type = ArrayContainer.MakeType (ec.Module, array_element_type, dimensions);
                        eclass = ExprClass.Value;
                        return this;
                }
@@ -8952,19 +8952,19 @@ namespace Mono.CSharp
                                        ec.Module.Compiler.Report.Error (719, loc, "Array elements cannot be of static type `{0}'",
                                                type.GetSignatureForError ());
                                } else {
-                                       MakeArray (single_spec);
+                                       MakeArray (ec.Module, single_spec);
                                }
                        }
 
                        return this;
                }
 
-               void MakeArray (ComposedTypeSpecifier spec)
+               void MakeArray (ModuleContainer module, ComposedTypeSpecifier spec)
                {
                        if (spec.Next != null)
-                               MakeArray (spec.Next);
+                               MakeArray (module, spec.Next);
 
-                       type = ArrayContainer.MakeType (type, spec.Dimension);
+                       type = ArrayContainer.MakeType (module, type, spec.Dimension);
                }
 
                public override string GetSignatureForError ()
index 780ed2bd75569a6b76357334983d8446f4d53e8c..50bcfe928e07dd54595e6b8e11726b0380c4741b 100644 (file)
@@ -1105,17 +1105,19 @@ namespace Mono.CSharp {
                readonly TypeSpec type;
                readonly TypeParameterSpec[] tparams;
                readonly TypeSpec[] targs;
+               readonly IModuleContext context;
 
                public TypeParameterInflator (TypeParameterInflator nested, TypeSpec type)
-                       : this (type, nested.tparams, nested.targs)
+                       : this (nested.context, type, nested.tparams, nested.targs)
                {
                }
 
-               public TypeParameterInflator (TypeSpec type, TypeParameterSpec[] tparams, TypeSpec[] targs)
+               public TypeParameterInflator (IModuleContext context, TypeSpec type, TypeParameterSpec[] tparams, TypeSpec[] targs)
                {
                        if (tparams.Length != targs.Length)
                                throw new ArgumentException ("Invalid arguments");
 
+                       this.context = context;
                        this.tparams = tparams;
                        this.targs = targs;
                        this.type = type;
@@ -1123,8 +1125,16 @@ namespace Mono.CSharp {
 
                #region Properties
 
+               public IModuleContext Context {
+                       get {
+                               return context;
+                       }
+               }
+
                public TypeSpec TypeInstance {
-                       get { return type; }
+                       get {
+                               return type;
+                       }
                }
 
                //
@@ -1148,7 +1158,7 @@ namespace Mono.CSharp {
                        if (ac != null) {
                                var et = Inflate (ac.Element);
                                if (et != ac.Element)
-                                       return ArrayContainer.MakeType (et, ac.Rank);
+                                       return ArrayContainer.MakeType (context.Module, et, ac.Rank);
 
                                return ac;
                        }
@@ -1190,7 +1200,7 @@ namespace Mono.CSharp {
                                        for (; i < targs.Length; ++i)
                                                inflated_targs[i] = Inflate (targs[i]);
 
-                                       type = type.MakeGenericType (inflated_targs);
+                                       type = type.MakeGenericType (context, inflated_targs);
                                }
 
                                return type;
@@ -1219,7 +1229,7 @@ namespace Mono.CSharp {
                                        targs[i++] = Inflate (ds_tp);
                        }
 
-                       return type.MakeGenericType (targs);
+                       return type.MakeGenericType (context, targs);
                }
 
                public TypeSpec Inflate (TypeParameterSpec tp)
@@ -1338,14 +1348,16 @@ namespace Mono.CSharp {
                TypeSpec[] targs;
                TypeParameterSpec[] constraints;
                readonly TypeSpec open_type;
+               readonly IModuleContext context;
 
-               public InflatedTypeSpec (TypeSpec openType, TypeSpec declaringType, TypeSpec[] targs)
+               public InflatedTypeSpec (IModuleContext context, TypeSpec openType, TypeSpec declaringType, TypeSpec[] targs)
                        : base (openType.Kind, declaringType, openType.MemberDefinition, null, openType.Modifiers)
                {
                        if (targs == null)
                                throw new ArgumentNullException ("targs");
 
 //                     this.state = openType.state;
+                       this.context = context;
                        this.open_type = openType;
                        this.targs = targs;
 
@@ -1377,7 +1389,7 @@ namespace Mono.CSharp {
                public TypeParameterSpec[] Constraints {
                        get {
                                if (constraints == null) {
-                                       constraints = TypeParameterSpec.InflateConstraints (MemberDefinition.TypeParameters, l => l.CreateLocalInflator (), this);
+                                       constraints = TypeParameterSpec.InflateConstraints (MemberDefinition.TypeParameters, l => l.CreateLocalInflator (context), this);
                                }
 
                                return constraints;
@@ -1422,7 +1434,7 @@ namespace Mono.CSharp {
                        return false;
                }
 
-               TypeParameterInflator CreateLocalInflator ()
+               TypeParameterInflator CreateLocalInflator (IModuleContext context)
                {
                        TypeParameterSpec[] tparams_full;
                        TypeSpec[] targs_full = targs;
@@ -1471,7 +1483,7 @@ namespace Mono.CSharp {
                                tparams_full = open_type.MemberDefinition.TypeParameters;
                        }
 
-                       return new TypeParameterInflator (this, tparams_full, targs_full);
+                       return new TypeParameterInflator (context, this, tparams_full, targs_full);
                }
 
                MetaType CreateMetaInfo (TypeParameterMutator mutator)
@@ -1550,7 +1562,7 @@ namespace Mono.CSharp {
                        if (cache == null)
                                cache = new MemberCache (onlyTypes ? open_type.MemberCacheTypes : open_type.MemberCache);
 
-                       var inflator = CreateLocalInflator ();
+                       var inflator = CreateLocalInflator (context);
 
                        //
                        // Two stage inflate due to possible nested types recursive
@@ -1857,7 +1869,7 @@ namespace Mono.CSharp {
                        //
                        // Now bind the parameters
                        //
-                       type = open_type.MakeGenericType (atypes);
+                       type = open_type.MakeGenericType (ec, atypes);
 
                        //
                        // Check constraints when context is not method/base type
@@ -2896,7 +2908,7 @@ namespace Mono.CSharp {
                // Uses inferred or partially infered types to inflate delegate type argument. Returns
                // null when type parameter has not been fixed
                //
-               public TypeSpec InflateGenericArgument (TypeSpec parameter)
+               public TypeSpec InflateGenericArgument (IModuleContext context, TypeSpec parameter)
                {
                        var tp = parameter as TypeParameterSpec;
                        if (tp != null) {
@@ -2919,14 +2931,14 @@ namespace Mono.CSharp {
                        if (gt != null) {
                                var inflated_targs = new TypeSpec [gt.TypeArguments.Length];
                                for (int ii = 0; ii < inflated_targs.Length; ++ii) {
-                                       var inflated = InflateGenericArgument (gt.TypeArguments [ii]);
+                                       var inflated = InflateGenericArgument (context, gt.TypeArguments [ii]);
                                        if (inflated == null)
                                                return null;
 
                                        inflated_targs[ii] = inflated;
                                }
 
-                               return gt.GetDefinition ().MakeGenericType (inflated_targs);
+                               return gt.GetDefinition ().MakeGenericType (context, inflated_targs);
                        }
 
                        return parameter;
@@ -3171,7 +3183,7 @@ namespace Mono.CSharp {
                                // if all delegate generic arguments are fixed.
                                TypeSpec[] param_types = new TypeSpec [invoke.Parameters.Count];
                                for (int i = 0; i < param_types.Length; ++i) {
-                                       var inflated = InflateGenericArgument (invoke.Parameters.Types[i]);
+                                       var inflated = InflateGenericArgument (ec, invoke.Parameters.Types[i]);
                                        if (inflated == null)
                                                return 0;
 
index 9dc5a528261aa49aa9b107021de352a31f83541c..097d67157cf06bb795d7fa244a2d28f8b9352a3e 100644 (file)
@@ -47,7 +47,8 @@ namespace Mono.CSharp
 
        sealed class StaticImporter : MetadataImporter
        {
-               public StaticImporter ()
+               public StaticImporter (ModuleContainer module)
+                       : base (module)
                {
                }
 
index 3d9066bd67afccee78a9aed4010f4c9ac05de31c..6a424239a644247d4340e075880ab2671f0907ac 100644 (file)
@@ -120,11 +120,14 @@ namespace Mono.CSharp
                protected readonly Dictionary<MetaType, TypeSpec> import_cache;
                protected readonly Dictionary<MetaType, TypeSpec> compiled_types;
                protected readonly Dictionary<Assembly, IAssemblyDefinition> assembly_2_definition;
+               readonly ModuleContainer module;
 
                public static readonly string CompilerServicesNamespace = "System.Runtime.CompilerServices";
 
-               protected MetadataImporter ()
+               protected MetadataImporter (ModuleContainer module)
                {
+                       this.module = module;
+
                        import_cache = new Dictionary<MetaType, TypeSpec> (1024, ReferenceEquality<MetaType>.Default);
                        compiled_types = new Dictionary<MetaType, TypeSpec> (40, ReferenceEquality<MetaType>.Default);
                        assembly_2_definition = new Dictionary<Assembly, IAssemblyDefinition> (ReferenceEquality<Assembly>.Default);
@@ -307,7 +310,7 @@ namespace Mono.CSharp
                                                throw new NotImplementedException ("Unknown element type " + type.ToString ());
                                        }
 
-                                       spec = ArrayContainer.MakeType (spec, type.GetArrayRank ());
+                                       spec = ArrayContainer.MakeType (module, spec, type.GetArrayRank ());
                                } else {
                                        spec = CreateType (type, dtype, true);
 
@@ -323,7 +326,7 @@ namespace Mono.CSharp
                                        //
                                        if (!IsMissingType (type) && type.IsGenericTypeDefinition) {
                                                var targs = CreateGenericArguments (0, type.GetGenericArguments (), dtype);
-                                               spec = spec.MakeGenericType (targs);
+                                               spec = spec.MakeGenericType (module, targs);
                                        }
                                }
 
@@ -669,7 +672,7 @@ namespace Mono.CSharp
                                if (declaringType == null) {
                                        // Simple case, no nesting
                                        spec = CreateType (type_def, null, new DynamicTypeReader (), canImportBaseType);
-                                       spec = spec.MakeGenericType (targs);
+                                       spec = spec.MakeGenericType (module, targs);
                                } else {
                                        //
                                        // Nested type case, converting .NET types like
@@ -684,7 +687,7 @@ namespace Mono.CSharp
 
                                        int targs_pos = 0;
                                        if (declaringType.Arity > 0) {
-                                               spec = declaringType.MakeGenericType (targs.Skip (targs_pos).Take (declaringType.Arity).ToArray ());
+                                               spec = declaringType.MakeGenericType (module, targs.Skip (targs_pos).Take (declaringType.Arity).ToArray ());
                                                targs_pos = spec.Arity;
                                        } else {
                                                spec = declaringType;
@@ -694,7 +697,7 @@ namespace Mono.CSharp
                                                var t = nested_hierarchy [i - 1];
                                                spec = MemberCache.FindNestedType (spec, t.Name, t.Arity);
                                                if (t.Arity > 0) {
-                                                       spec = spec.MakeGenericType (targs.Skip (targs_pos).Take (spec.Arity).ToArray ());
+                                                       spec = spec.MakeGenericType (module, targs.Skip (targs_pos).Take (spec.Arity).ToArray ());
                                                        targs_pos += t.Arity;
                                                }
                                        }
@@ -706,7 +709,7 @@ namespace Mono.CSharp
 
                                        spec = MemberCache.FindNestedType (spec, name, targs.Length - targs_pos);
                                        if (spec.Arity > 0) {
-                                               spec = spec.MakeGenericType (targs.Skip (targs_pos).ToArray ());
+                                               spec = spec.MakeGenericType (module, targs.Skip (targs_pos).ToArray ());
                                        }
                                }
 
@@ -1060,7 +1063,7 @@ namespace Mono.CSharp
                                var spec = ImportType (element, dtype);
 
                                if (type.IsArray)
-                                       return ArrayContainer.MakeType (spec, type.GetArrayRank ());
+                                       return ArrayContainer.MakeType (module, spec, type.GetArrayRank ());
                                if (type.IsByRef)
                                        return ReferenceContainer.MakeType (spec);
                                if (type.IsPointer)
index 0de7fe4bc9a0a0e57735c40e5a443f3b737cd384..424a90f782e560081d709e03934dd9a31331ec78 100644 (file)
@@ -89,7 +89,7 @@ namespace Mono.CSharp {
                                // When type inference context exists try to apply inferred type arguments
                                //
                                if (tic != null) {
-                                       d_param = tic.InflateGenericArgument (d_param);
+                                       d_param = tic.InflateGenericArgument (ec, d_param);
                                }
 
                                ptypes [i] = d_param;
index d8088fc154bd8f2ac1dff20cacae703c66cb4b57..7d19c487f3db5d45f85ad5da907a1e632921f695 100644 (file)
@@ -116,7 +116,7 @@ namespace Mono.CSharp.Linq
                                                TypeInferenceContext tic = new TypeInferenceContext (source_type.TypeArguments);
                                                tic.OutputTypeInference (rc, a.Expr, source_type);
                                                if (tic.FixAllTypes (rc)) {
-                                                       source_type = source_type.GetDefinition ().MakeGenericType (tic.InferredTypeArguments);
+                                                       source_type = source_type.GetDefinition ().MakeGenericType (rc, tic.InferredTypeArguments);
                                                }
                                        }
 
index 1d7f3b3c8d67641d5a1abcad67ebdba29af178eb..737ebb04de36bc4ce8ba79bb7f96aecd7326804f 100644 (file)
@@ -392,7 +392,7 @@ namespace Mono.CSharp {
                        return ms;
                }
 
-               public MethodSpec MakeGenericMethod (params TypeSpec[] targs)
+               public MethodSpec MakeGenericMethod (IMemberContext context, params TypeSpec[] targs)
                {
                        if (targs == null)
                                throw new ArgumentNullException ();
@@ -403,7 +403,7 @@ namespace Mono.CSharp {
                        //if (generic_intances == null)
                        //    generic_intances = new Dictionary<TypeSpec[], Method> (TypeSpecArrayComparer.Default);
 
-                       var inflator = new TypeParameterInflator (DeclaringType, GenericDefinition.TypeParameters, targs);
+                       var inflator = new TypeParameterInflator (context, DeclaringType, GenericDefinition.TypeParameters, targs);
 
                        var inflated = (MethodSpec) MemberwiseClone ();
                        inflated.declaringType = inflator.TypeInstance;
@@ -1031,7 +1031,7 @@ namespace Mono.CSharp {
                                        var local_tparam = tp.Type;
                                        local_tparam.SpecialConstraint = base_tparam.SpecialConstraint;
 
-                                       var inflator = new TypeParameterInflator (CurrentType, base_decl_tparams, base_targs);
+                                       var inflator = new TypeParameterInflator (this, CurrentType, base_decl_tparams, base_targs);
                                        base_tparam.InflateConstraints (inflator, local_tparam);
 
                                        //
index a480676356fcf2ce612c066cd4b2f47234f49601..986d21e4c57c5a709f3acb19a3352d4140979e5a 100644 (file)
@@ -22,7 +22,7 @@ namespace Mono.CSharp
 #if STATIC
        public class ReflectionImporter
        {
-               public ReflectionImporter (BuildinTypes buildin)
+               public ReflectionImporter (ModuleContainer module, BuildinTypes buildin)
                {
                        throw new NotSupportedException ();
                }
@@ -45,7 +45,8 @@ namespace Mono.CSharp
 #else
        public sealed class ReflectionImporter : MetadataImporter
        {
-               public ReflectionImporter (BuildinTypes buildin)
+               public ReflectionImporter (ModuleContainer module, BuildinTypes buildin)
+                       : base (module)
                {
                        Initialize (buildin);
                }
index b92de64dcc4082cf09b4f37ace51bf402b15d780..83da55288ca7b4c7105c99817891f4e6291aa9ae 100644 (file)
@@ -610,14 +610,13 @@ namespace Mono.CSharp {
                                                return ParseResult.Error;
                                        }
                                        packages = String.Join (" ", value.Split (new Char[] { ';', ',', '\n', '\r' }));
-                                       string pkgout = Driver.GetPackageFlags (packages, true, report);
+                                       string pkgout = Driver.GetPackageFlags (packages, report);
 
-                                       if (pkgout != null) {
-                                               string[] xargs = pkgout.Trim (new Char[] { ' ', '\n', '\r', '\t' }).
-                                                       Split (new Char[] { ' ', '\t' });
-                                               args = AddArgs (args, xargs);
-                                       }
+                                       if (pkgout == null)
+                                               return ParseResult.Error;
 
+                                       string[] xargs = pkgout.Trim (new Char[] { ' ', '\n', '\r', '\t' }).Split (new Char[] { ' ', '\t' });
+                                       args = AddArgs (args, xargs);
                                        return ParseResult.Success;
                                }
 
index c448081e1402dc97f95b73b0c8de023ba227e05a..55c65df9a85262fcb0734948596de5cc03a13951 100644 (file)
@@ -120,6 +120,7 @@ namespace Mono.CSharp
                public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
 
                Dictionary<int, List<AnonymousTypeClass>> anonymous_types;
+               Dictionary<ArrayContainer.TypeRankPair, ArrayContainer> arrays;
 
                AssemblyDefinition assembly;
                readonly CompilerContext context;
@@ -146,10 +147,17 @@ namespace Mono.CSharp
                        anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
                        global_ns = new GlobalRootNamespace ();
                        alias_ns = new Dictionary<string, RootNamespace> ();
+                       arrays = new Dictionary<ArrayContainer.TypeRankPair, ArrayContainer> ();
                }
 
                #region Properties
 
+               public Dictionary<ArrayContainer.TypeRankPair, ArrayContainer> ArraysCache {
+                       get {
+                               return arrays;
+                       }
+               }
+
                public override AttributeTargets AttributeTargets {
                        get {
                                return AttributeTargets.Assembly;
index 4ddf17a1a29565655d8fce2b19336b8c5820176d..8dce7a920f15c3555c69d41e9591e661701c810a 100644 (file)
@@ -310,7 +310,7 @@ namespace Mono.CSharp
                string ns;
                int arity;
                MemberKind kind;
-               ModuleContainer module;
+               protected readonly ModuleContainer module;
                protected TypeSpec type;
 
                public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
index 488ad0d533022d151867942012d1a54218afe15f..40465158e9b37f3b3184ffba3777833d64c2433f 100644 (file)
@@ -387,13 +387,13 @@ namespace Mono.CSharp
                        // because type parameters are same for all nested types
                        //
                        if (DeclaringType == inflator.TypeInstance) {
-                               return MakeGenericType (targs);
+                               return MakeGenericType (inflator.Context, targs);
                        }
 
-                       return new InflatedTypeSpec (this, inflator.TypeInstance, targs);
+                       return new InflatedTypeSpec (inflator.Context, this, inflator.TypeInstance, targs);
                }
 
-               public InflatedTypeSpec MakeGenericType (TypeSpec[] targs)
+               public InflatedTypeSpec MakeGenericType (IModuleContext context, TypeSpec[] targs)
                {
                        if (targs.Length == 0 && !IsNested)
                                throw new ArgumentException ("Empty type arguments for type " + GetSignatureForError ());
@@ -421,7 +421,7 @@ namespace Mono.CSharp
                                        throw new InternalErrorException ("`{0}' must be type definition or nested non-inflated type to MakeGenericType",
                                                GetSignatureForError ());
 
-                               instance = new InflatedTypeSpec (this, declaringType, targs);
+                               instance = new InflatedTypeSpec (context, this, declaringType, targs);
                                inflated_instances.Add (targs, instance);
                        }
 
@@ -1274,7 +1274,7 @@ namespace Mono.CSharp
 
        public class ArrayContainer : ElementTypeSpec
        {
-               struct TypeRankPair : IEquatable<TypeRankPair>
+               public struct TypeRankPair : IEquatable<TypeRankPair>
                {
                        TypeSpec ts;
                        int rank;
@@ -1301,11 +1301,12 @@ namespace Mono.CSharp
                }
 
                readonly int rank;
-               static Dictionary<TypeRankPair, ArrayContainer> instances = new Dictionary<TypeRankPair, ArrayContainer> ();
+               readonly ModuleContainer module;
 
-               private ArrayContainer (TypeSpec element, int rank)
+               private ArrayContainer (ModuleContainer module, TypeSpec element, int rank)
                        : base (MemberKind.ArrayType, element, null)
                {
+                       this.module = module;
                        this.rank = rank;
                }
 
@@ -1317,7 +1318,7 @@ namespace Mono.CSharp
 
                public MethodInfo GetConstructor ()
                {
-                       var mb = RootContext.ToplevelTypes.Builder;
+                       var mb = module.Builder;
 
                        var arg_types = new MetaType[rank];
                        for (int i = 0; i < rank; i++)
@@ -1333,7 +1334,7 @@ namespace Mono.CSharp
 
                public MethodInfo GetAddressMethod ()
                {
-                       var mb = RootContext.ToplevelTypes.Builder;
+                       var mb = module.Builder;
 
                        var arg_types = new MetaType[rank];
                        for (int i = 0; i < rank; i++)
@@ -1349,7 +1350,7 @@ namespace Mono.CSharp
 
                public MethodInfo GetGetMethod ()
                {
-                       var mb = RootContext.ToplevelTypes.Builder;
+                       var mb = module.Builder;
 
                        var arg_types = new MetaType[rank];
                        for (int i = 0; i < rank; i++)
@@ -1365,7 +1366,7 @@ namespace Mono.CSharp
 
                public MethodInfo GetSetMethod ()
                {
-                       var mb = RootContext.ToplevelTypes.Builder;
+                       var mb = module.Builder;
 
                        var arg_types = new MetaType[rank + 1];
                        for (int i = 0; i < rank; i++)
@@ -1410,30 +1411,25 @@ namespace Mono.CSharp
                        return sb.ToString ();
                }
 
-               public static ArrayContainer MakeType (TypeSpec element)
+               public static ArrayContainer MakeType (ModuleContainer module, TypeSpec element)
                {
-                       return MakeType (element, 1);
+                       return MakeType (module, element, 1);
                }
 
-               public static ArrayContainer MakeType (TypeSpec element, int rank)
+               public static ArrayContainer MakeType (ModuleContainer module, TypeSpec element, int rank)
                {
                        ArrayContainer ac;
                        var key = new TypeRankPair (element, rank);
-                       if (!instances.TryGetValue (key, out ac)) {
-                               ac = new ArrayContainer (element, rank) {
+                       if (!module.ArraysCache.TryGetValue (key, out ac)) {
+                               ac = new ArrayContainer (module, element, rank) {
                                        BaseType = TypeManager.array_type
                                };
 
-                               instances.Add (key, ac);
+                               module.ArraysCache.Add (key, ac);
                        }
 
                        return ac;
                }
-
-               public static void Reset ()
-               {
-                       instances = new Dictionary<TypeRankPair, ArrayContainer> ();
-               }
        }
 
        class ReferenceContainer : ElementTypeSpec