Improve handling of netmodules. Fixes #504085
authorMarek Safar <marek.safar@gmail.com>
Sun, 21 Nov 2010 10:48:36 +0000 (10:48 +0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 22 Nov 2010 09:52:54 +0000 (09:52 +0000)
23 files changed:
mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/CSharpBinder.cs
mcs/errors/cs1681-2.cs
mcs/errors/cs1681.cs
mcs/mcs/assembly.cs
mcs/mcs/attribute.cs
mcs/mcs/class.cs
mcs/mcs/const.cs
mcs/mcs/context.cs
mcs/mcs/cs-parser.jay
mcs/mcs/doc.cs
mcs/mcs/driver.cs
mcs/mcs/eval.cs
mcs/mcs/expression.cs
mcs/mcs/field.cs
mcs/mcs/import.cs
mcs/mcs/namespace.cs
mcs/mcs/parameter.cs
mcs/mcs/roottypes.cs
mcs/mcs/typemanager.cs
mcs/tests/known-issues-dmcs
mcs/tests/known-issues-gmcs
mcs/tests/ver-il-dmcs.xml
mcs/tests/ver-il-gmcs.xml

index 2b6c0252abe9024ee62809fc21d7c36ddd81942b..4dc57447afcc4e8126fd02bf42595f0518438202 100644 (file)
@@ -173,9 +173,6 @@ namespace Microsoft.CSharp.RuntimeBinder
                                }
 
                                importer.Initialize ();
-                               // Import all currently loaded assemblies
-                               var ns = cc.GlobalRootNamespace;
-                               var domain = AppDomain.CurrentDomain;
 
                                //
                                // Any later loaded assemblies are handled internally by GetAssemblyDefinition
@@ -186,14 +183,17 @@ namespace Microsoft.CSharp.RuntimeBinder
                                //
                                Compiler.RootContext.ToplevelTypes = new Compiler.ModuleContainer (cc);
                                var temp = Compiler.RootContext.ToplevelTypes.MakeExecutable ("dynamic");
-                               temp.Create (AppDomain.CurrentDomain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
+
+                               // Import all currently loaded assemblies
+                               var domain = AppDomain.CurrentDomain;
+
+                               temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
                                foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
-                                       ns.AddAssemblyReference (a);
-                                       importer.ImportAssembly (ns.CreateAssemblyDefinition (a), ns);
+                                       importer.ImportAssembly (a, Compiler.RootContext.ToplevelTypes.GlobalRootNamespace);
                                }
 
                                if (!Compiler.RootContext.EvalMode) {
-                                       Compiler.TypeManager.InitCoreTypes (cc, core_types);
+                                       Compiler.TypeManager.InitCoreTypes (Compiler.RootContext.ToplevelTypes, core_types);
                                        Compiler.TypeManager.InitOptionalCoreTypes (cc);
                                }
 
index 0a7dfe840808e2fa17e814871776b38e313fa093..d9ac6112f4078b3553ef4b9e159caadab60adf7d 100644 (file)
@@ -1,3 +1,3 @@
-// CS1681: You cannot redefine the global extern alias
+// CS1681: The global extern alias cannot be redefined
 // Line: 0
 // Compiler options: -r:global=CS1681-2-lib.dll
index 563ccbf138416cc100275f84681d13cc3369ba09..097ed8b18e9847c9e1275f8a4edb3d7438283d67 100644 (file)
@@ -1,4 +1,4 @@
-// cs1681.cs: You cannot redefine the global extern alias
+// CS1681: The global extern alias cannot be redefined
 // Line: 3
 extern alias global;
 using System;
index 3f48d136f14e8480ba6a8188ffaf4574ebd1f0fe..d88a4fbd82ea0b64df0d7be59103cd70c15e44ff 100644 (file)
@@ -38,6 +38,8 @@ namespace Mono.CSharp
        {
                // TODO: make it private and move all builder based methods here
                public AssemblyBuilder Builder;
+               AssemblyBuilderExtension builder_extra;
+
                bool is_cls_compliant;
                bool wrap_non_exception_throws;
                bool wrap_non_exception_throws_custom;
@@ -51,9 +53,10 @@ namespace Mono.CSharp
 
                Attribute cls_attribute;
 
+               List<ImportedModuleDefinition> added_modules;
                Dictionary<SecurityAction, PermissionSet> declarative_security;
-               MethodInfo add_type_forwarder;
                Dictionary<ITypeDefinition, Attribute> emitted_forwarders;
+               AssemblyAttributesPlaceholder module_target_attrs;
 
                //
                // In-memory only assembly container
@@ -144,6 +147,17 @@ namespace Mono.CSharp
 
                #endregion
 
+               public void AddModule (string moduleFile)
+               {
+                       var mod = builder_extra.AddModule (moduleFile);
+                       var imported = Compiler.MetaImporter.ImportModule (mod, module.GlobalRootNamespace);
+
+                       if (added_modules == null) {
+                               added_modules = new List<ImportedModuleDefinition> ();
+                               added_modules.Add (imported);
+                       }
+               }               
+
                public void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
                {
                        if (a.IsValidSecurityAttribute ()) {
@@ -164,11 +178,13 @@ namespace Mono.CSharp
                                        return;
                                }
 
-                               try {
-                                       var fi = typeof (AssemblyBuilder).GetField ("culture", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
-                                       fi.SetValue (Builder, value == "neutral" ? "" : value);
-                               } catch {
-                                       Report.RuntimeMissingSupport (a.Location, "AssemblyCultureAttribute setting");
+                               if (value == "neutral")
+                                       value = "";
+
+                               if (RootContext.Target == Target.Module) {
+                                       SetCustomAttribute (ctor, cdata);
+                               } else {
+                                       builder_extra.SetCulture (value, a.Location);
                                }
 
                                return;
@@ -185,11 +201,10 @@ namespace Mono.CSharp
                                        return;
                                }
 
-                               try {
-                                       var fi = typeof (AssemblyBuilder).GetField ("version", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
-                                       fi.SetValue (Builder, vinfo);
-                               } catch {
-                                       Report.RuntimeMissingSupport (a.Location, "AssemblyVersionAttribute setting");
+                               if (RootContext.Target == Target.Module) {
+                                       SetCustomAttribute (ctor, cdata);
+                               } else {
+                                       builder_extra.SetVersion (vinfo, a.Location);
                                }
 
                                return;
@@ -202,11 +217,10 @@ namespace Mono.CSharp
                                alg |= ((uint) cdata [pos + 2]) << 16;
                                alg |= ((uint) cdata [pos + 3]) << 24;
 
-                               try {
-                                       var fi = typeof (AssemblyBuilder).GetField ("algid", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
-                                       fi.SetValue (Builder, alg);
-                               } catch {
-                                       Report.RuntimeMissingSupport (a.Location, "AssemblyAlgorithmIdAttribute setting");
+                               if (RootContext.Target == Target.Module) {
+                                       SetCustomAttribute (ctor, cdata);
+                               } else {
+                                       builder_extra.SetAlgorithmId (alg, a.Location);
                                }
 
                                return;
@@ -223,11 +237,10 @@ namespace Mono.CSharp
                                if ((flags & (uint) AssemblyNameFlags.PublicKey) != 0 && public_key == null)
                                        flags &= ~(uint) AssemblyNameFlags.PublicKey;
 
-                               try {
-                                       var fi = typeof (AssemblyBuilder).GetField ("flags", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
-                                       fi.SetValue (Builder, flags);
-                               } catch {
-                                       Report.RuntimeMissingSupport (a.Location, "AssemblyFlagsAttribute setting");
+                               if (RootContext.Target == Target.Module) {
+                                       SetCustomAttribute (ctor, cdata);
+                               } else {
+                                       builder_extra.SetFlags (flags, a.Location);
                                }
 
                                return;
@@ -264,17 +277,7 @@ namespace Mono.CSharp
                                        return;
                                }
 
-                               if (add_type_forwarder == null) {
-                                       add_type_forwarder = typeof (AssemblyBuilder).GetMethod ("AddTypeForwarder",
-                                               BindingFlags.NonPublic | BindingFlags.Instance);
-
-                                       if (add_type_forwarder == null) {
-                                               Report.RuntimeMissingSupport (a.Location, "TypeForwardedTo attribute");
-                                               return;
-                                       }
-                               }
-
-                               add_type_forwarder.Invoke (Builder, new object[] { t.GetMetaInfo () });
+                               builder_extra.AddTypeForwarder (t, a.Location);
                                return;
                        }
 
@@ -316,7 +319,7 @@ namespace Mono.CSharp
                                wrap_non_exception_throws_custom = true;
                        }
 
-                       Builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
+                       SetCustomAttribute (ctor, cdata);
                }
 
                //
@@ -328,7 +331,7 @@ namespace Mono.CSharp
                {
                        // TODO: It should check only references assemblies but there is
                        // no working SRE API
-                       foreach (var a in Compiler.GlobalRootNamespace.Assemblies) {
+                       foreach (var a in Compiler.MetaImporter.Assemblies) {
                                if (public_key != null && !a.HasStrongName) {
                                        Report.Error (1577, "Referenced assembly `{0}' does not have a strong name",
                                                a.FullName);
@@ -383,6 +386,8 @@ namespace Mono.CSharp
                                throw;
                        }
 
+                       builder_extra = new AssemblyBuilderExtension (Builder, Compiler);
+
                        return true;
                }
 
@@ -429,21 +434,35 @@ namespace Mono.CSharp
 
                public void Emit ()
                {
-                       module.Emit ();
+                       if (RootContext.Target == Target.Module) {
+                               module_target_attrs = new AssemblyAttributesPlaceholder (module);
+                               module_target_attrs.CreateType ();
+                               module_target_attrs.DefineType ();
+                               module_target_attrs.Define ();
+                               module.AddCompilerGeneratedClass (module_target_attrs);
+                       } else if (added_modules != null) {
+                               ReadModulesAssemblyAttributes ();
+                       }
 
-                       if (module.HasExtensionMethod)
-                               Compiler.PredefinedAttributes.Extension.EmitAttribute (Builder);
+                       module.Emit ();
 
-                       PredefinedAttribute pa = Compiler.PredefinedAttributes.RuntimeCompatibility;
-                       if (pa.IsDefined && !wrap_non_exception_throws_custom) {
-                               var ci = TypeManager.GetPredefinedConstructor (pa.Type, Location.Null, TypeSpec.EmptyTypes);
-                               PropertyInfo [] pis = new PropertyInfo [1];
+                       if (module.HasExtensionMethod) {
+                               var pa = Compiler.PredefinedAttributes.Extension;
+                               if (pa.IsDefined) {
+                                       SetCustomAttribute (pa.Constructor, AttributeEncoder.Empty);
+                               }
+                       }
 
-                               pis [0] = TypeManager.GetPredefinedProperty (pa.Type,
-                                       "WrapNonExceptionThrows", Location.Null, TypeManager.bool_type).MetaInfo;
-                               object [] pargs = new object [1];
-                               pargs [0] = true;
-                               Builder.SetCustomAttribute (new CustomAttributeBuilder ((ConstructorInfo) ci.GetMetaInfo (), new object[0], pis, pargs));
+                       if (!wrap_non_exception_throws_custom) {
+                               PredefinedAttribute pa = Compiler.PredefinedAttributes.RuntimeCompatibility;
+                               if (pa.IsDefined && pa.ResolveBuilder ()) {
+                                       var prop = pa.GetProperty ("WrapNonExceptionThrows", TypeManager.bool_type, Location.Null);
+                                       if (prop != null) {
+                                               AttributeEncoder encoder = new AttributeEncoder (false);
+                                               encoder.EncodeNamedPropertyArgument (prop, new BoolLiteral (true, Location.Null));
+                                               SetCustomAttribute (pa.Constructor, encoder.ToArray ());
+                                       }
+                               }
                        }
 
                        if (declarative_security != null) {
@@ -562,6 +581,17 @@ namespace Mono.CSharp
                        }
                }
 
+               void ReadModulesAssemblyAttributes ()
+               {
+                       foreach (var m in added_modules) {
+                               var cattrs = m.ReadAssemblyAttributes ();
+                               if (cattrs == null)
+                                       continue;
+
+                               module.OptAttributes.AddAttributes (cattrs);
+                       }
+               }
+
                public void Resolve ()
                {
                        if (RootContext.Unsafe) {
@@ -581,7 +611,7 @@ namespace Mono.CSharp
                                Arguments named = new Arguments (1);
                                named.Add (new NamedArgument ("SkipVerification", loc, new BoolLiteral (true, loc)));
 
-                               GlobalAttribute g = new GlobalAttribute (new NamespaceEntry (Compiler, null, null, null), "assembly",
+                               GlobalAttribute g = new GlobalAttribute (new NamespaceEntry (module, null, null, null), "assembly",
                                        new MemberAccess (system_security_permissions, "SecurityPermissionAttribute"),
                                        new Arguments[] { pos, named }, loc, false);
                                g.AttachTo (module, module);
@@ -605,6 +635,16 @@ namespace Mono.CSharp
                                is_cls_compliant = cls_attribute.GetClsCompliantAttributeValue ();
                        }
 
+                       if (added_modules != null && RootContext.VerifyClsCompliance && is_cls_compliant) {
+                               foreach (var m in added_modules) {
+                                       if (!m.IsCLSCompliant) {
+                                               Report.Error (3013,
+                                                       "Added modules must be marked with the CLSCompliant attribute to match the assembly",
+                                                       m.Name);
+                                       }
+                               }
+                       }
+
                        Attribute a = module.ResolveAssemblyAttribute (Compiler.PredefinedAttributes.RuntimeCompatibility);
                        if (a != null) {
                                var val = a.GetPropertyValue ("WrapNonExceptionThrows") as BoolConstant;
@@ -712,16 +752,13 @@ namespace Mono.CSharp
                                machine = ImageFileMachine.I386;
                                break;
                        }
+
+                       if (RootContext.Target == Target.Module) {
+                               builder_extra.SetModuleTarget ();
+                       }
+
                        try {
                                Builder.Save (module.Builder.ScopeName, pekind, machine);
-                       } catch (System.Runtime.InteropServices.COMException) {
-                               if ((RootContext.StrongNameKeyFile == null) || (!RootContext.StrongNameDelaySign))
-                                       throw;
-
-                               // FIXME: it seems Microsoft AssemblyBuilder doesn't like to delay sign assemblies 
-                               Report.Error (1548, "Couldn't delay-sign the assembly with the '" +
-                                       RootContext.StrongNameKeyFile +
-                                       "', Use MCS with the Mono runtime or CSC to compile this assembly.");
                        } catch (System.IO.IOException io) {
                                Report.Error (16, "Could not write to file `" + name + "', cause: " + io.Message);
                                return;
@@ -734,6 +771,14 @@ namespace Mono.CSharp
                        }
                }
 
+               void SetCustomAttribute (MethodSpec ctor, byte[] data)
+               {
+                       if (module_target_attrs != null)
+                               module_target_attrs.AddAssemblyAttribute (ctor, data);
+                       else
+                               Builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), data);
+               }
+
                void Error_ObsoleteSecurityAttribute (Attribute a, string option)
                {
                        Report.Warning (1699, 1, a.Location,
@@ -767,30 +812,144 @@ namespace Mono.CSharp
 
                        return new Version (v.Major, System.Math.Max (0, v.Minor), System.Math.Max (0, v.Build), System.Math.Max (0, v.Revision)).ToString (4);
                }
+       }
+
+       //
+       // A placeholder class for assembly attributes when emitting module
+       //
+       class AssemblyAttributesPlaceholder : CompilerGeneratedClass
+       {
+               public static readonly string TypeName = "<$AssemblyAttributes>";
+               public static readonly string AssemblyFieldName = "attributes";
+
+               Field assembly;
+
+               public AssemblyAttributesPlaceholder (ModuleContainer parent)
+                       : base (parent, new MemberName (TypeName), Modifiers.STATIC)
+               {
+                       assembly = new Field (this, new TypeExpression (TypeManager.object_type, Location), Modifiers.PUBLIC | Modifiers.STATIC,
+                               new MemberName (AssemblyFieldName), null);
+
+                       AddField (assembly);
+               }
 
+               public void AddAssemblyAttribute (MethodSpec ctor, byte[] data)
+               {
+                       assembly.SetCustomAttribute (ctor, data);
+               }
+       }
 
-               // Wrapper for AssemblyBuilder.AddModule
+       //
+       // Extension to System.Reflection.Emit.AssemblyBuilder to have fully compatible
+       // compiler
+       //
+       class AssemblyBuilderExtension
+       {
                static MethodInfo adder_method;
-               static public MethodInfo AddModule_Method {
-                       get {
+               static MethodInfo set_module_only;
+               static MethodInfo add_type_forwarder;
+               static FieldInfo assembly_version;
+               static FieldInfo assembly_algorithm;
+               static FieldInfo assembly_culture;
+               static FieldInfo assembly_flags;
+
+               AssemblyBuilder builder;
+               CompilerContext ctx;
+
+               public AssemblyBuilderExtension (AssemblyBuilder ab, CompilerContext ctx)
+               {
+                       this.builder = ab;
+                       this.ctx = ctx;
+               }
+
+               public Module AddModule (string module)
+               {
+                       try {
                                if (adder_method == null)
-                                       adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance|BindingFlags.NonPublic);
-                               return adder_method;
+                                       adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance | BindingFlags.NonPublic);
+
+                               return (Module) adder_method.Invoke (builder, new object[] { module });
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (Location.Null, "-addmodule");
+                               return null;
                        }
                }
-               public Module AddModule (string module)
+
+               public void AddTypeForwarder (TypeSpec type, Location loc)
                {
-                       MethodInfo m = AddModule_Method;
-                       if (m == null) {
-                               Report.RuntimeMissingSupport (Location.Null, "/addmodule");
-                               Environment.Exit (1);
+                       try {
+                               if (add_type_forwarder == null) {
+                                       add_type_forwarder = typeof (AssemblyBuilder).GetMethod ("AddTypeForwarder", BindingFlags.NonPublic | BindingFlags.Instance);
+                               }
+
+                               add_type_forwarder.Invoke (builder, new object[] { type.GetMetaInfo () });
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (loc, "TypeForwardedToAttribute");
                        }
+               }
 
+               public void SetAlgorithmId (uint value, Location loc)
+               {
                        try {
-                               return (Module) m.Invoke (Builder, new object [] { module });
-                       } catch (TargetInvocationException ex) {
-                               throw ex.InnerException;
+                               if (assembly_algorithm == null)
+                                       assembly_algorithm = typeof (AssemblyBuilder).GetField ("algid", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
+
+                               assembly_algorithm.SetValue (builder, value);
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (loc, "AssemblyAlgorithmIdAttribute");
                        }
-               }               
+               }
+
+               public void SetCulture (string culture, Location loc)
+               {
+                       try {
+                               if (assembly_culture == null)
+                                       assembly_culture = typeof (AssemblyBuilder).GetField ("culture", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
+
+                               assembly_culture.SetValue (builder, culture);
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (loc, "AssemblyCultureAttribute");
+                       }
+               }
+
+
+               public void SetFlags (uint flags, Location loc)
+               {
+                       try {
+                               if (assembly_flags == null)
+                                       assembly_flags = typeof (AssemblyBuilder).GetField ("flags", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
+
+                               assembly_flags.SetValue (builder, flags);
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (loc, "AssemblyFlagsAttribute");
+                       }
+
+               }
+
+               public void SetVersion (string version, Location loc)
+               {
+                       try {
+                               if (assembly_version == null)
+                                       assembly_version = typeof (AssemblyBuilder).GetField ("version", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
+
+                               assembly_version.SetValue (builder, version);
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (loc, "AssemblyVersionAttribute");
+                       }
+               }
+
+               public void SetModuleTarget ()
+               {
+                       try {
+                               if (set_module_only == null) {
+                                       var module_only = typeof (AssemblyBuilder).GetProperty ("IsModuleOnly", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+                                       set_module_only = module_only.GetSetMethod (true);
+                               }
+
+                               set_module_only.Invoke (builder, new object[] { true });
+                       } catch {
+                               ctx.Report.RuntimeMissingSupport (Location.Null, "-target:module");
+                       }
+               }
        }
 }
index 4a052933052308955bbcd07cbc7ae6f79210c243..fde8c287394090615d7c01475df962e04a4f5301 100644 (file)
@@ -102,7 +102,7 @@ namespace Mono.CSharp {
                static Assembly orig_sec_assembly;
                public static readonly object[] EmptyObject = new object [0];
 
-               IList<KeyValuePair<MemberExpr, NamedArgument>> named_values;
+               List<KeyValuePair<MemberExpr, NamedArgument>> named_values;
 
                // Cache for parameter-less attributes
                static Dictionary<TypeSpec, MethodSpec> att_cache;
@@ -1111,7 +1111,7 @@ namespace Mono.CSharp {
                                        na.Value.Expr.EncodeAttributeValue (context, encoder, na.Key.Type);
                                }
                        } else {
-                               encoder.Stream.Write ((ushort) 0);
+                               encoder.EncodeEmptyNamedArguments ();
                        }
 
                        byte[] cdata = encoder.ToArray ();
@@ -1398,8 +1398,18 @@ namespace Mono.CSharp {
                        TypeParameter = 1 << 1
                }
 
+               const ushort Version = 1;
+
+               public static readonly byte[] Empty;
+
                public readonly BinaryWriter Stream;
 
+               static AttributeEncoder ()
+               {
+                       Empty = new byte[4];
+                       Array.Copy (BitConverter.GetBytes (Version), Empty, 2);
+               }
+
                public AttributeEncoder (bool empty)
                {
                        if (empty) {
@@ -1408,8 +1418,22 @@ namespace Mono.CSharp {
                        }
 
                        Stream = new BinaryWriter (new MemoryStream ());
-                       const ushort version = 1;
-                       Stream.Write (version);
+                       Stream.Write (Version);
+               }
+
+               public void Encode (byte value)
+               {
+                       Stream.Write (value);
+               }
+
+               public void Encode (int value)
+               {
+                       Stream.Write (value);
+               }
+
+               public void Encode (uint value)
+               {
+                       Stream.Write (value);
                }
 
                public void Encode (string value)
@@ -1474,6 +1498,35 @@ namespace Mono.CSharp {
                        Encode (type.MemberDefinition.IsImported ? old_type.AssemblyQualifiedName : old_type.FullName);
                }
 
+               //
+               // Encodes single property named argument per call
+               //
+               public void EncodeNamedPropertyArgument (PropertySpec property, Constant value)
+               {
+                       Stream.Write ((ushort) 1);      // length
+                       Stream.Write ((byte) 0x54); // property
+                       Encode (property.MemberType);
+                       Encode (property.Name);
+                       value.EncodeAttributeValue (null, this, property.MemberType);
+               }
+
+               //
+               // Encodes single field named argument per call
+               //
+               public void EncodeNamedFieldArgument (FieldSpec field, Constant value)
+               {
+                       Stream.Write ((ushort) 1);      // length
+                       Stream.Write ((byte) 0x53); // field
+                       Encode (field.MemberType);
+                       Encode (field.Name);
+                       value.EncodeAttributeValue (null, this, field.MemberType);
+               }
+
+               public void EncodeEmptyNamedArguments ()
+               {
+                       Stream.Write ((ushort) 0);
+               }
+
                void WriteCompressedValue (int value)
                {
                        if (value < 0x80) {
@@ -1552,23 +1605,6 @@ namespace Mono.CSharp {
                        return result;
                }
 
-               public static void VerifyModulesClsCompliance (CompilerContext ctx)
-               {
-                       Module[] modules = ctx.GlobalRootNamespace.Modules;
-                       if (modules == null)
-                               return;
-
-                       // The first module is generated assembly
-                       for (int i = 1; i < modules.Length; ++i) {
-                               Module module = modules [i];
-                               if (!GetClsCompliantAttributeValue (module, null)) {
-                                       ctx.Report.Error (3013, "Added modules must be marked with the CLSCompliant attribute " +
-                                                     "to match the assembly", module.Name);
-                                       return;
-                               }
-                       }
-               }
-
                static bool GetClsCompliantAttributeValue (ICustomAttributeProvider attribute_provider, Assembly a) 
                {
                        object[] cls_attr = attribute_provider.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
@@ -1627,6 +1663,7 @@ namespace Mono.CSharp {
                public readonly PredefinedAttribute AttributeUsage;
                public readonly PredefinedAttribute DefaultParameterValue;
                public readonly PredefinedAttribute OptionalParameter;
+               public readonly PredefinedAttribute UnverifiableCode;
 
                // New in .NET 2.0
                public readonly PredefinedAttribute DefaultCharset;
@@ -1648,7 +1685,7 @@ namespace Mono.CSharp {
                // Optional types which are used as types and for member lookup
                //
                public readonly PredefinedAttribute DefaultMember;
-               public readonly PredefinedAttribute DecimalConstant;
+               public readonly PredefinedDecimalAttribute DecimalConstant;
                public readonly PredefinedAttribute StructLayout;
                public readonly PredefinedAttribute FieldOffset;
 
@@ -1677,6 +1714,7 @@ namespace Mono.CSharp {
                        AttributeUsage = new PredefinedAttribute ("System", "AttributeUsageAttribute");
                        DefaultParameterValue = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultParameterValueAttribute");
                        OptionalParameter = new PredefinedAttribute ("System.Runtime.InteropServices", "OptionalAttribute");
+                       UnverifiableCode = new PredefinedAttribute ("System.Security", "UnverifiableCodeAttribute");
 
                        DefaultCharset = new PredefinedAttribute ("System.Runtime.InteropServices", "DefaultCharSetAttribute");
                        TypeForwarder = new PredefinedAttribute ("System.Runtime.CompilerServices", "TypeForwardedToAttribute");
@@ -1692,7 +1730,7 @@ namespace Mono.CSharp {
                        Dynamic = new PredefinedDynamicAttribute ("System.Runtime.CompilerServices", "DynamicAttribute");
 
                        DefaultMember = new PredefinedAttribute ("System.Reflection", "DefaultMemberAttribute");
-                       DecimalConstant = new PredefinedAttribute ("System.Runtime.CompilerServices", "DecimalConstantAttribute");
+                       DecimalConstant = new PredefinedDecimalAttribute ("System.Runtime.CompilerServices", "DecimalConstantAttribute");
                        StructLayout = new PredefinedAttribute ("System.Runtime.InteropServices", "StructLayoutAttribute");
                        FieldOffset = new PredefinedAttribute ("System.Runtime.InteropServices", "FieldOffsetAttribute");
                }
@@ -1708,10 +1746,11 @@ namespace Mono.CSharp {
        public class PredefinedAttribute
        {
                protected TypeSpec type;
-               CustomAttributeBuilder cab;
-               MethodSpec ctor;
+               protected MethodSpec ctor;
                readonly string ns, name;
                CompilerContext compiler;
+               List<FieldSpec> fields;
+               List<PropertySpec> properties;
 
                static readonly TypeSpec NotFound = InternalType.Null;
 
@@ -1721,6 +1760,29 @@ namespace Mono.CSharp {
                        this.name = name;
                }
 
+               #region Properties
+
+               public MethodSpec Constructor {
+                       get {
+                               return ctor;
+                       }
+               }
+
+               public bool IsDefined {
+                       get {
+                               return type != null && type != NotFound;
+                       }
+               }
+
+               public TypeSpec Type {
+                       get {
+                               return type;
+                       }
+               }
+
+               #endregion
+
+
                public static bool operator == (TypeSpec type, PredefinedAttribute pa)
                {
                        return type == pa.type;
@@ -1731,10 +1793,6 @@ namespace Mono.CSharp {
                        return type != pa.type;
                }
 
-               public ConstructorInfo Constructor {
-                       get { return ctor == null ? null : (ConstructorInfo) ctor.GetMetaInfo (); }
-               }
-
                public override int GetHashCode ()
                {
                        return base.GetHashCode ();
@@ -1753,47 +1811,118 @@ namespace Mono.CSharp {
                public void EmitAttribute (ConstructorBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
                }
 
                public void EmitAttribute (MethodBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
                }
 
                public void EmitAttribute (PropertyBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
                }
 
                public void EmitAttribute (FieldBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
+               }
+
+               public void EmitAttribute (FieldBuilder builder, AttributeEncoder argsEncoded)
+               {
+                       builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ());
                }
 
                public void EmitAttribute (TypeBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
+               }
+
+               public void EmitAttribute (TypeBuilder builder, AttributeEncoder argsEncoded)
+               {
+                       builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ());
                }
 
                public void EmitAttribute (AssemblyBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
+               }
+
+               public void EmitAttribute (ModuleBuilder builder)
+               {
+                       if (ResolveBuilder ())
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
                }
 
                public void EmitAttribute (ParameterBuilder builder)
                {
                        if (ResolveBuilder ())
-                               builder.SetCustomAttribute (cab);
+                               builder.SetCustomAttribute (GetCtorMetaInfo (), AttributeEncoder.Empty);
                }
 
-               public bool IsDefined {
-                       get { return type != null && type != NotFound; }
+               public void EmitAttribute (ParameterBuilder builder, AttributeEncoder argsEncoded)
+               {
+                       builder.SetCustomAttribute (GetCtorMetaInfo (), argsEncoded.ToArray ());
+               }
+
+               ConstructorInfo GetCtorMetaInfo ()
+               {
+                       return (ConstructorInfo) ctor.GetMetaInfo ();
+               }
+
+               public FieldSpec GetField (string name, TypeSpec memberType, Location loc)
+               {
+                       FieldSpec spec;
+                       if (fields != null) {
+                               spec = fields.Find (l => l.Name == name);
+                       } else {
+                               spec = null;
+                       }
+
+                       if (spec == null) {
+                               spec = TypeManager.GetPredefinedField (type, name, loc, memberType);
+
+                               if (spec != null) {
+                                       if (fields == null) {
+                                               fields = new List<FieldSpec> ();
+                                       }
+
+                                       fields.Add (spec);
+                               }
+                       }
+
+                       return spec;
+               }
+
+               public PropertySpec GetProperty (string name, TypeSpec memberType, Location loc)
+               {
+                       PropertySpec spec;
+
+                       if (properties != null) {
+                               spec = properties.Find (l => l.Name == name);
+                       } else {
+                               spec = null;
+                       }
+
+                       if (spec == null) {
+                               spec = TypeManager.GetPredefinedProperty (type, name, loc, memberType);
+
+                               if (spec != null) {
+                                       if (properties == null) {
+                                               properties = new List<PropertySpec> ();
+                                       }
+
+                                       properties.Add (spec);
+                               }
+                       }
+
+                       return spec;
                }
 
                public void Initialize (CompilerContext ctx, bool canFail)
@@ -1820,9 +1949,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               bool ResolveBuilder ()
+               public bool ResolveBuilder ()
                {
-                       if (cab != null)
+                       if (ctor != null)
                                return true;
 
                        //
@@ -1831,12 +1960,8 @@ namespace Mono.CSharp {
                        if (!Resolve (true))
                                return false;
 
-                       var ci = TypeManager.GetPredefinedConstructor (type, Location.Null, TypeSpec.EmptyTypes);
-                       if (ci == null)
-                               return false;
-
-                       cab = new CustomAttributeBuilder ((ConstructorInfo) ci.GetMetaInfo (), new object[0]);
-                       return true;
+                       ctor = TypeManager.GetPredefinedConstructor (type, Location.Null, TypeSpec.EmptyTypes);
+                       return ctor != null;
                }
 
                public bool ResolveConstructor (Location loc, params TypeSpec[] argType)
@@ -1850,9 +1975,53 @@ namespace Mono.CSharp {
                        ctor = TypeManager.GetPredefinedConstructor (type, loc, argType);
                        return ctor != null;
                }
+       }
 
-               public TypeSpec Type {
-                       get { return type; }
+       public class PredefinedDecimalAttribute : PredefinedAttribute
+       {
+               public PredefinedDecimalAttribute (string ns, string name)
+                       : base (ns, name)
+               {
+               }
+
+               public void EmitAttribute (ParameterBuilder builder, decimal value, Location loc)
+               {
+                       if (!Resolve (false))
+                               return;
+
+                       if (ctor == null && !ResolveConstructor (loc, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
+                               return;
+
+                       int[] bits = decimal.GetBits (value);
+                       AttributeEncoder encoder = new AttributeEncoder (false);
+                       encoder.Encode ((byte) (bits[3] >> 16));
+                       encoder.Encode ((byte) (bits[3] >> 31));
+                       encoder.Encode ((uint) bits[2]);
+                       encoder.Encode ((uint) bits[1]);
+                       encoder.Encode ((uint) bits[0]);
+                       encoder.EncodeEmptyNamedArguments ();
+
+                       EmitAttribute (builder, encoder);
+               }
+
+               public void EmitAttribute (FieldBuilder builder, decimal value, Location loc)
+               {
+                       if (!Resolve (false))
+                               return;
+
+                       if (ctor == null && !ResolveConstructor (loc, TypeManager.byte_type, TypeManager.byte_type, TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
+                               return;
+
+                       int[] bits = decimal.GetBits (value);
+                       AttributeEncoder encoder = new AttributeEncoder (false);
+                       encoder.Encode ((byte) (bits[3] >> 16));
+                       encoder.Encode ((byte) (bits[3] >> 31));
+                       encoder.Encode ((uint) bits[2]);
+                       encoder.Encode ((uint) bits[1]);
+                       encoder.Encode ((uint) bits[0]);
+                       encoder.EncodeEmptyNamedArguments ();
+
+                       EmitAttribute (builder, encoder);
                }
        }
 
index 20ffe93389b693ada3ce3ec04b97b7068435fffc..9b48935451f03432ba6165ccd06c01bce2047c3e 100644 (file)
@@ -1011,7 +1011,8 @@ namespace Mono.CSharp {
                        int type_size = Kind == MemberKind.Struct && first_nonstatic_field == null ? 1 : 0;
 
                        if (IsTopLevel) {
-                               if (Compiler.GlobalRootNamespace.IsNamespace (Name)) {
+                               // TODO: Completely wrong
+                               if (Module.GlobalRootNamespace.IsNamespace (Name)) {
                                        Report.Error (519, Location, "`{0}' clashes with a predefined namespace", Name);
                                }
 
@@ -1629,8 +1630,11 @@ namespace Mono.CSharp {
                                !pa.ResolveConstructor (Location, TypeManager.string_type))
                                return;
 
-                       CustomAttributeBuilder cb = new CustomAttributeBuilder (pa.Constructor, new string [] { GetAttributeDefaultMember () });
-                       TypeBuilder.SetCustomAttribute (cb);
+                       var encoder = new AttributeEncoder (false);
+                       encoder.Encode (GetAttributeDefaultMember ());
+                       encoder.EncodeEmptyNamedArguments ();
+
+                       pa.EmitAttribute (TypeBuilder, encoder);
                }
 
                protected virtual void CheckEqualsAndGetHashCode ()
index ec4634a0fe6b2e52ebb62e9fa8e7ca0d9690244d..64804ec65b5cb48b515be5c61dbb094bd8d3aa9c 100644 (file)
@@ -86,7 +86,7 @@ namespace Mono.CSharp {
                {
                        var c = ((ConstSpec) spec).Value as Constant;
                        if (c.Type == TypeManager.decimal_type) {
-                               FieldBuilder.SetCustomAttribute (CreateDecimalConstantAttribute (c, Compiler.PredefinedAttributes));
+                               Compiler.PredefinedAttributes.DecimalConstant.EmitAttribute (FieldBuilder, (decimal) c.GetValue (), c.Location);
                        } else {
                                FieldBuilder.SetConstant (c.GetTypedValue ());
                        }
@@ -94,25 +94,6 @@ namespace Mono.CSharp {
                        base.Emit ();
                }
 
-               public static CustomAttributeBuilder CreateDecimalConstantAttribute (Constant c, PredefinedAttributes pa)
-               {
-                       PredefinedAttribute attr = pa.DecimalConstant;
-                       if (attr.Constructor == null &&
-                               !attr.ResolveConstructor (c.Location, TypeManager.byte_type, TypeManager.byte_type,
-                                       TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
-                               return null;
-
-                       Decimal d = (Decimal) c.GetValue ();
-                       int [] bits = Decimal.GetBits (d);
-                       object [] args = new object [] { 
-                               (byte) (bits [3] >> 16),
-                               (byte) (bits [3] >> 31),
-                               (uint) bits [2], (uint) bits [1], (uint) bits [0]
-                       };
-
-                       return new CustomAttributeBuilder (attr.Constructor, args);
-               }
-
                public static void Error_InvalidConstantType (TypeSpec t, Location loc, Report Report)
                {
                        if (t.IsGenericParameter) {
index a3221526e58f14432759e264dd3aa1f30765d7a6..150af102253c6d916506a7a9ed9fa7805d535746 100644 (file)
@@ -547,7 +547,6 @@ namespace Mono.CSharp
                readonly Report report;
                readonly ReflectionMetaImporter meta_importer;
                readonly PredefinedAttributes attributes;
-               readonly GlobalRootNamespace root;
 
                public CompilerContext (ReflectionMetaImporter metaImporter, Report report)
                {
@@ -555,16 +554,12 @@ namespace Mono.CSharp
                        this.report = report;
 
                        this.attributes = new PredefinedAttributes ();
-                       this.root = new GlobalRootNamespace ();
                }
 
                #region Properties
 
-               public GlobalRootNamespace GlobalRootNamespace {
-                       get {
-                               return root;
-                       }
-               }
+               // TODO: Obsolete, it has to go
+               public RootNamespace GlobalRootNamespace { get; set; }
 
                public bool IsRuntimeBinder { get; set; }
 
index 99fea1d3d396a256eab82e3b6a5915dccfb43ffd..d264990896ea3d60860c3cdc161b56f4186a2ecf 100644 (file)
@@ -473,7 +473,7 @@ namespace_declaration
                        Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
                }
 
-               current_namespace = new NamespaceEntry (compiler,
+               current_namespace = new NamespaceEntry (module,
                        current_namespace, file, name.GetName ());
                current_class = current_namespace.SlaveDeclSpace;
                current_container = current_class.PartialContainer;
@@ -6150,7 +6150,7 @@ public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleCo
        this.file = file;
        this.module = module;
        this.compiler = module.Compiler;
-       current_namespace = new NamespaceEntry (compiler, null, file, null);
+       current_namespace = new NamespaceEntry (module, null, file, null);
        current_class = current_namespace.SlaveDeclSpace;
        current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
        oob_stack.Clear ();
index 25c61c248ab415c5be5efdf1f520769467c9a732..b145f201d273568ec82b06ad61ee3517f5ab0150 100644 (file)
@@ -323,7 +323,7 @@ namespace Mono.CSharp {
                        var nsName = identifier.Substring (0, index);
                        var typeName = identifier.Substring (index + 1);
                        Namespace ns = ds.NamespaceEntry.NS.GetNamespace (nsName, false);
-                       ns = ns ?? mc.Compiler.GlobalRootNamespace.GetNamespace(nsName, false);
+                       ns = ns ?? mc.Module.GlobalRootNamespace.GetNamespace(nsName, false);
                        if (ns != null) {
                                var te = ns.LookupType(mc.Compiler, typeName, 0, true, mc.Location);
                                if(te != null)
@@ -625,7 +625,7 @@ namespace Mono.CSharp {
                                xref.SetAttribute ("cref", "N:" + ns.GetSignatureForError ());
                                return; // a namespace
                        }
-                       if (mc.Compiler.GlobalRootNamespace.IsNamespace (name)) {
+                       if (mc.Module.GlobalRootNamespace.IsNamespace (name)) {
                                xref.SetAttribute ("cref", "N:" + name);
                                return; // a namespace
                        }
index 69985be35dffa350842441a7566deae7f7d46aed..bc964c0d90b19db5568627c32f02ee3964a1a22f 100644 (file)
@@ -317,11 +317,6 @@ namespace Mono.CSharp
                        return 1;
                }
 
-               public void LoadAssembly (string assembly, bool soft)
-               {
-                       LoadAssembly (assembly, null, soft);
-               }
-
                void Error6 (string name, string log)
                {
                        if (log != null && log.Length > 0)
@@ -338,7 +333,7 @@ namespace Mono.CSharp
 
                void BadAssembly (string filename, string log)
                {
-                       MethodInfo adder_method = AssemblyDefinition.AddModule_Method;
+                       MethodInfo adder_method = null; // AssemblyDefinition.AddModule_Method;
 
                        if (adder_method != null) {
                                AssemblyName an = new AssemblyName ();
@@ -368,7 +363,7 @@ namespace Mono.CSharp
                        Error9 ("assembly", filename, log);
                }
 
-               public void LoadAssembly (string assembly, string alias, bool soft)
+               public Assembly LoadAssemblyFile (string assembly, bool soft)
                {
                        Assembly a = null;
                        string total_log = "";
@@ -398,22 +393,15 @@ namespace Mono.CSharp
                                                        break;
                                                } catch (FileNotFoundException ff) {
                                                        if (soft)
-                                                               return;
+                                                               return a;
                                                        total_log += ff.FusionLog;
                                                }
                                        }
                                        if (err) {
                                                Error6 (assembly, total_log);
-                                               return;
+                                               return a;
                                        }
                                }
-
-                               // Extern aliased refs require special handling
-                               if (alias == null)
-                                       ctx.GlobalRootNamespace.AddAssemblyReference (a);
-                               else
-                                       ctx.GlobalRootNamespace.DefineRootNamespace (alias, a, ctx);
-
                        } catch (BadImageFormatException f) {
                                // .NET 2.0 throws this if we try to load a module without an assembly manifest ...
                                BadAssembly (f.FileName, f.FusionLog);
@@ -421,16 +409,17 @@ namespace Mono.CSharp
                                // ... while .NET 1.1 throws this
                                BadAssembly (f.FileName, f.FusionLog);
                        }
+
+                       return a;
                }
 
-               public void LoadModule (AssemblyDefinition assembly, string module)
+               void LoadModule (AssemblyDefinition assembly, string module)
                {
-                       Module m = null;
                        string total_log = "";
 
                        try {
                                try {
-                                       m = assembly.AddModule (module);
+                                       assembly.AddModule (module);
                                } catch (FileNotFoundException) {
                                        bool err = true;
                                        foreach (string dir in link_paths) {
@@ -439,7 +428,7 @@ namespace Mono.CSharp
                                                        full_path += ".netmodule";
 
                                                try {
-                                                       m = assembly.AddModule (full_path);
+                                                       assembly.AddModule (full_path);
                                                        err = false;
                                                        break;
                                                } catch (FileNotFoundException ff) {
@@ -451,9 +440,6 @@ namespace Mono.CSharp
                                                return;
                                        }
                                }
-
-                               ctx.GlobalRootNamespace.AddModuleReference (m);
-
                        } catch (BadImageFormatException f) {
                                Error9 ("module", f.FileName, f.FusionLog);
                        } catch (FileLoadException f) {
@@ -464,32 +450,65 @@ namespace Mono.CSharp
                /// <summary>
                ///   Loads all assemblies referenced on the command line
                /// </summary>
-               public void LoadReferences ()
+               public void LoadReferences (ModuleContainer module)
                {
                        link_paths.Add (GetSystemDir ());
                        link_paths.Add (Directory.GetCurrentDirectory ());
+                       Assembly a;
+                       var loaded = new List<Tuple<RootNamespace, Assembly>> ();
 
                        //
                        // Load Core Library for default compilation
                        //
-                       if (RootContext.StdLib)
-                               LoadAssembly ("mscorlib", false);
+                       if (RootContext.StdLib) {
+                               a = LoadAssemblyFile ("mscorlib", false);
+                               if (a != null)
+                                       loaded.Add (Tuple.Create (module.GlobalRootNamespace, a));
+                       }
 
-                       foreach (string r in soft_references)
-                               LoadAssembly (r, true);
+                       foreach (string r in soft_references) {
+                               a = LoadAssemblyFile (r, true);
+                               if (a != null)
+                                       loaded.Add (Tuple.Create (module.GlobalRootNamespace, a));
+                       }
 
-                       foreach (string r in references)
-                               LoadAssembly (r, false);
+                       foreach (string r in references) {
+                               a = LoadAssemblyFile (r, false);
+                               if (a == null)
+                                       continue;
 
-                       foreach (var entry in external_aliases)
-                               LoadAssembly (entry.Value, entry.Key, false);
+                               var key = Tuple.Create (module.GlobalRootNamespace, a);
+                               if (loaded.Contains (key))
+                                       continue;
 
-                       if (modules.Count > 0) {
-                               foreach (string module in modules)
-                                       LoadModule (null, module);
+                               loaded.Add (key);
+                       }
+
+                       foreach (var entry in external_aliases) {
+                               a = LoadAssemblyFile (entry.Value, false);
+                               if (a == null)
+                                       continue;
+
+                               var key = Tuple.Create (module.CreateRootNamespace (entry.Key), a);
+                               if (loaded.Contains (key))
+                                       continue;
+
+                               loaded.Add (key);
+                       }
+
+                       foreach (var entry in loaded) {
+                               ctx.MetaImporter.ImportAssembly (entry.Item2, entry.Item1);
+                       }
+               }
+
+               void LoadModules (AssemblyDefinition assembly)
+               {
+                       if (modules.Count == 0)
+                               return;
+
+                       foreach (var module in modules) {
+                               LoadModule (assembly, module);
                        }
-                               
-                       ctx.GlobalRootNamespace.ComputeNamespaces (ctx);
                }
 
                static string [] LoadArgs (string file)
@@ -1691,8 +1710,6 @@ namespace Mono.CSharp
                                        output_file = first_source + RootContext.TargetExt;
                        }
 
-                       ctx.GlobalRootNamespace.AddModuleReference (RootContext.ToplevelTypes.Builder);
-
                        //
                        // Load assemblies required
                        //
@@ -1703,11 +1720,11 @@ namespace Mono.CSharp
 
                        var assembly = module.MakeExecutable (output_file, output_file);
                        
-                       LoadReferences ();              
+                       LoadReferences (module);
                
                        ShowTime ("Imporing referenced assemblies");
                        
-                       if (!TypeManager.InitCoreTypes (ctx, ctypes))
+                       if (!TypeManager.InitCoreTypes (module, ctypes))
                                return false;
 
                        TypeManager.InitOptionalCoreTypes (ctx);
@@ -1717,16 +1734,7 @@ namespace Mono.CSharp
                        if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
                                return false;
 
-                       if (RootContext.Target == Target.Module) {
-                               PropertyInfo module_only = typeof (AssemblyBuilder).GetProperty ("IsModuleOnly", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
-                               if (module_only == null) {
-                                       Report.RuntimeMissingSupport (Location.Null, "/target:module");
-                                       Environment.Exit (1);
-                               }
-
-                               MethodInfo set_method = module_only.GetSetMethod (true);
-                               set_method.Invoke (assembly.Builder, BindingFlags.Default, null, new object[] { true }, null);
-                       }
+                       LoadModules (assembly);
 
                        module.Define ();
 
@@ -1752,11 +1760,6 @@ namespace Mono.CSharp
 
                        assembly.Resolve ();
                        
-                       if (RootContext.VerifyClsCompliance) {
-                               if (assembly.IsCLSCompliant) {
-                                       AttributeTester.VerifyModulesClsCompliance (ctx);
-                               }
-                       }
                        if (Report.Errors > 0)
                                return false;
                        
index 65c7f42d0c9693dc2f4050d5a16c21bf3b08506a..18ad70a5073b30404d7eabd35df31e5494ac3ce0 100644 (file)
@@ -133,8 +133,8 @@ namespace Mono.CSharp {
                                ctx.MetaImporter.Initialize ();
 
                                RootContext.ToplevelTypes.MakeExecutable ("temp");
-                               driver.LoadReferences ();
-                               TypeManager.InitCoreTypes (ctx, ctypes);
+                               driver.LoadReferences (RootContext.ToplevelTypes);
+                               TypeManager.InitCoreTypes (RootContext.ToplevelTypes, ctypes);
                                TypeManager.InitOptionalCoreTypes (ctx);
 
                                RootContext.EvalMode = true;
@@ -152,7 +152,6 @@ namespace Mono.CSharp {
                static void Reset ()
                {
                        CompilerCallableEntryPoint.PartialReset ();
-                       RootContext.PartialReset ();
                        
                        Location.AddFile (null, "{interactive}");
                        Location.Initialize ();
@@ -244,7 +243,7 @@ namespace Mono.CSharp {
                                if (!inited)
                                        Init ();
 
-                               RootContext.ToplevelTypes = new ModuleContainer (ctx);
+                       //      RootContext.ToplevelTypes = new ModuleContainer (ctx);
 
                                bool partial_input;
                                CSharpParser parser = ParseString (ParseMode.Silent, input, out partial_input);
@@ -630,7 +629,7 @@ namespace Mono.CSharp {
                        }
                        seekable.Position = 0;
 
-                       CSharpParser parser = new CSharpParser (seekable, (CompilationUnit) Location.SourceFiles [0], RootContext.ToplevelTypes);
+                       CSharpParser parser = new CSharpParser (seekable, Location.SourceFiles [0], RootContext.ToplevelTypes);
 
                        if (kind == InputKind.StatementOrExpression){
                                parser.Lexer.putback_char = Tokenizer.EvalStatementParserCharacter;
@@ -876,8 +875,9 @@ namespace Mono.CSharp {
                static public void LoadAssembly (string file)
                {
                        lock (evaluator_lock){
-                               driver.LoadAssembly (file, false);
-                               ctx.GlobalRootNamespace.ComputeNamespaces (ctx);
+                               var a = driver.LoadAssemblyFile (file, false);
+                               if (a != null)
+                                       ctx.MetaImporter.ImportAssembly (a, RootContext.ToplevelTypes.GlobalRootNamespace);
                        }
                }
 
@@ -887,9 +887,7 @@ namespace Mono.CSharp {
                static public void ReferenceAssembly (Assembly a)
                {
                        lock (evaluator_lock){
-//                             GlobalRootNamespace.Instance.AddAssemblyReference (a);
-//                             GlobalRootNamespace.Instance.ComputeNamespaces (ctx);
-                               ctx.MetaImporter.ImportAssembly (new ImportedAssemblyDefinition (a), ctx.GlobalRootNamespace);
+                               ctx.MetaImporter.ImportAssembly (a, RootContext.ToplevelTypes.GlobalRootNamespace);
                        }
                }
 
index c6eadcaa0718fe65919a0d1682f0dd017c4ea866..46540ad1741976ccdf7444b0f76a69b261ada9d3 100644 (file)
@@ -7450,7 +7450,7 @@ namespace Mono.CSharp {
                public override FullNamedExpression ResolveAsTypeStep (IMemberContext ec, bool silent)
                {
                        if (alias == GlobalAlias) {
-                               expr = ec.Compiler.GlobalRootNamespace;
+                               expr = ec.CurrentMemberDefinition.Module.GlobalRootNamespace;
                                return base.ResolveAsTypeStep (ec, silent);
                        }
 
index 267426a049ca97a7f3585a3dd37adc9bcdf0a9cd..897c94c481dc9bfbdb1d3e392c9c1138972f9ee4 100644 (file)
@@ -147,6 +147,11 @@ namespace Mono.CSharp
                        FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
                }
 
+               public void SetCustomAttribute (MethodSpec ctor, byte[] data)
+               {
+                       FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), data);
+               }
+
                protected override bool CheckBase ()
                {
                        if (!base.CheckBase ())
@@ -333,8 +338,6 @@ namespace Mono.CSharp
        {
                public const string FixedElementName = "FixedElementField";
                static int GlobalCounter = 0;
-               static object[] ctor_args = new object[] { (short)LayoutKind.Sequential };
-               static FieldInfo[] fi;
 
                TypeBuilder fixed_buffer_type;
 
@@ -438,25 +441,22 @@ namespace Mono.CSharp
 
                void EmitFieldSize (int buffer_size)
                {
-                       CustomAttributeBuilder cab;
                        PredefinedAttribute pa;
+                       AttributeEncoder encoder;
 
                        pa = Compiler.PredefinedAttributes.StructLayout;
-                       if (pa.Constructor == null &&
-                               !pa.ResolveConstructor (Location, TypeManager.short_type))
-                                       return;
+                       if (pa.Constructor == null && !pa.ResolveConstructor (Location, TypeManager.short_type))
+                               return;
+
+                       var field = pa.GetField ("Size", TypeManager.int32_type, Location);
+                       if (field != null) {
+                               encoder = new AttributeEncoder (false);
+                               encoder.Encode ((short)LayoutKind.Sequential);
+                               encoder.EncodeNamedFieldArgument (field, new IntConstant (buffer_size, Location));
 
-                       // TODO: It's not cleared
-                       if (fi == null) {
-                               var field = (FieldSpec) MemberCache.FindMember (pa.Type, MemberFilter.Field ("Size", null), BindingRestriction.DeclaredOnly);
-                               fi = new FieldInfo[] { field.GetMetaInfo () };
+                               pa.EmitAttribute (fixed_buffer_type, encoder);
                        }
 
-                       object[] fi_val = new object[] { buffer_size };
-                       cab = new CustomAttributeBuilder (pa.Constructor,
-                               ctor_args, fi, fi_val);
-                       fixed_buffer_type.SetCustomAttribute (cab);
-                       
                        //
                        // Don't emit FixedBufferAttribute attribute for private types
                        //
@@ -464,12 +464,15 @@ namespace Mono.CSharp
                                return;
 
                        pa = Compiler.PredefinedAttributes.FixedBuffer;
-                       if (pa.Constructor == null &&
-                               !pa.ResolveConstructor (Location, TypeManager.type_type, TypeManager.int32_type))
+                       if (pa.Constructor == null && !pa.ResolveConstructor (Location, TypeManager.type_type, TypeManager.int32_type))
                                return;
 
-                       cab = new CustomAttributeBuilder (pa.Constructor, new object[] { MemberType.GetMetaInfo (), buffer_size });
-                       FieldBuilder.SetCustomAttribute (cab);
+                       encoder = new AttributeEncoder (false);
+                       encoder.EncodeTypeName (MemberType);
+                       encoder.Encode (buffer_size);
+                       encoder.EncodeEmptyNamedArguments ();
+
+                       pa.EmitAttribute (FieldBuilder, encoder);
                }
 
                public void SetCharSet (TypeAttributes ta)
index 8a6aaa13fb7c23494f9751ce4ffa5d5296c84c66..4b3284f4f60f2a61ac46ead0fddad60a8bf46de4 100644 (file)
@@ -33,6 +33,12 @@ namespace Mono.CSharp
 
                #region Properties
 
+               public ICollection<ImportedAssemblyDefinition> Assemblies {
+                       get {
+                               return assembly_2_definition.Values;
+                       }
+               }
+
                public bool IgnorePrivateMembers { get; set; }
 
                #endregion
@@ -819,16 +825,19 @@ namespace Mono.CSharp
                        return null;
                }
 
-               public void ImportAssembly (ImportedAssemblyDefinition assembly, Namespace targetNamespace)
+               public void ImportAssembly (Assembly assembly, RootNamespace targetNamespace)
                {
                        // It can be used more than once when importing same assembly
                        // into 2 or more global aliases
-                       if (!assembly_2_definition.ContainsKey (assembly.Assembly)) {
-                               assembly_2_definition.Add (assembly.Assembly, assembly);
-                               assembly.ReadAttributes ();
+                       ImportedAssemblyDefinition definition;
+                       if (!assembly_2_definition.TryGetValue (assembly, out definition)) {
+                               definition = new ImportedAssemblyDefinition (assembly);
+                               assembly_2_definition.Add (assembly, definition);
+
+                               definition.ReadAttributes ();
                        }
 
-                       Type extension_type = assembly.HasExtensionMethod ? HasExtensionAttribute (CustomAttributeData.GetCustomAttributes (assembly.Assembly)) : null;
+                       Type extension_type = definition.HasExtensionMethod ? HasExtensionAttribute (CustomAttributeData.GetCustomAttributes (assembly)) : null;
 
                        //
                        // This part tries to simulate loading of top-level
@@ -838,7 +847,7 @@ namespace Mono.CSharp
                        //
                        Type[] all_types;
                        try {
-                               all_types = assembly.Assembly.GetTypes ();
+                               all_types = assembly.GetTypes ();
                        } catch (ReflectionTypeLoadException e) {
                                all_types = e.Types;
                        }
@@ -846,8 +855,11 @@ namespace Mono.CSharp
                        ImportTypes (all_types, targetNamespace, extension_type);
                }
 
-               public void ImportModule (Module module, Namespace targetNamespace)
+               public ImportedModuleDefinition ImportModule (Module module, RootNamespace targetNamespace)
                {
+                       var module_definition = new ImportedModuleDefinition (module, this);
+                       module_definition.ReadAttributes ();
+
                        Type extension_type = HasExtensionAttribute (CustomAttributeData.GetCustomAttributes (module));
 
                        Type[] all_types;
@@ -855,10 +867,11 @@ namespace Mono.CSharp
                                all_types = module.GetTypes ();
                        } catch (ReflectionTypeLoadException e) {
                                all_types = e.Types;
-                               throw;
                        }
 
                        ImportTypes (all_types, targetNamespace, extension_type);
+
+                       return module_definition;
                }
 
                void ImportTypes (Type[] types, Namespace targetNamespace, Type extension_type)
@@ -1152,6 +1165,82 @@ namespace Mono.CSharp
                }
        }
 
+       public class ImportedModuleDefinition
+       {
+               readonly Module module;
+               bool cls_compliant;
+               //ReflectionMetaImporter metaImporter;
+               
+               public ImportedModuleDefinition (Module module, ReflectionMetaImporter metaImporter)
+               {
+                       this.module = module;
+                       //this.metaImporter = metaImporter;
+               }
+
+               #region Properties
+
+               public bool IsCLSCompliant {
+                       get {
+                               return cls_compliant;
+                       }
+               }
+
+               public string Name {
+                       get {
+                               return module.Name;
+                       }
+               }
+
+               #endregion
+
+               public void ReadAttributes ()
+               {
+                       IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (module);
+                       foreach (var a in attrs) {
+                               var type = a.Constructor.DeclaringType;
+                               if (type == typeof (CLSCompliantAttribute)) {
+                                       cls_compliant = (bool) a.ConstructorArguments[0].Value;
+                                       continue;
+                               }
+                       }
+               }
+
+               //
+               // Reads assembly attributes which where attached to a special type because
+               // module does have assembly manifest
+               //
+               public List<Attribute> ReadAssemblyAttributes ()
+               {
+                       var t = module.GetType (AssemblyAttributesPlaceholder.TypeName);
+                       if (t == null)
+                               return null;
+
+                       var field = t.GetField (AssemblyAttributesPlaceholder.AssemblyFieldName, BindingFlags.NonPublic | BindingFlags.Static);
+                       if (field == null)
+                               return null;
+
+                       // TODO: implement, the idea is to fabricate specil Attribute class and
+                       // add it to OptAttributes before resolving the source code attributes
+                       // Need to build module location as well for correct error reporting
+
+                       //var assembly_attributes = CustomAttributeData.GetCustomAttributes (field);
+                       //var attrs = new List<Attribute> (assembly_attributes.Count);
+                       //foreach (var a in assembly_attributes)
+                       //{
+                       //    var type = metaImporter.ImportType (a.Constructor.DeclaringType);
+                       //    var ctor = metaImporter.CreateMethod (a.Constructor, type);
+
+                       //    foreach (var carg in a.ConstructorArguments) {
+                       //        carg.Value
+                       //    }
+
+                       //    attrs.Add (new Attribute ("assembly", ctor, null, Location.Null, true));
+                       //}
+
+                       return null;
+               }
+       }
+
        public class ImportedAssemblyDefinition : IAssemblyDefinition
        {
                readonly Assembly assembly;
index 56330e9d19b58ce2768bb90baeb992d220243ec5..ab649a5033a767aa5a2f8ad0e912ca7cd040395b 100644 (file)
@@ -17,37 +17,21 @@ namespace Mono.CSharp {
 
        public class RootNamespace : Namespace {
 
-               protected readonly string alias_name;
-               protected List<ImportedAssemblyDefinition> referenced_assemblies;
-
-               Dictionary<string, Namespace> all_namespaces;
+               readonly string alias_name;
+               readonly Dictionary<string, Namespace> all_namespaces;
 
                public RootNamespace (string alias_name)
                        : base (null, String.Empty)
                {
                        this.alias_name = alias_name;
-                       referenced_assemblies = new List<ImportedAssemblyDefinition> ();
 
                        all_namespaces = new Dictionary<string, Namespace> ();
                        all_namespaces.Add ("", this);
                }
 
-               public void AddAssemblyReference (ImportedAssemblyDefinition assembly)
-               {
-                       referenced_assemblies.Add (assembly);
-               }
-
-               public virtual void ImportTypes (CompilerContext ctx)
-               {
-                       foreach (var a in referenced_assemblies) {
-                               try {
-                                       ctx.MetaImporter.ImportAssembly (a, this);
-                               } catch (TypeLoadException e) {
-                                       ctx.Report.Error (11, Location.Null, e.Message);
-                               } catch (System.IO.FileNotFoundException) {
-                                       ctx.Report.Error (12, Location.Null, "An assembly `{0}' is used without being referenced",
-                                               a.FullName);
-                               }
+               public string Alias {
+                       get {
+                               return alias_name;
                        }
                }
 
@@ -74,82 +58,11 @@ namespace Mono.CSharp {
                }
        }
 
-       // TODO: It should go to AssemblyClass or AssemblySpec
-       public class GlobalRootNamespace : RootNamespace {
-               Module [] modules;
-               Dictionary<string, RootNamespace> root_namespaces;
-               Dictionary<Assembly, ImportedAssemblyDefinition> all_assemblies;
-
+       public class GlobalRootNamespace : RootNamespace
+       {
                public GlobalRootNamespace ()
                        : base ("global")
                {
-                       root_namespaces = new Dictionary<string, RootNamespace> ();
-                       root_namespaces.Add (alias_name, this);
-                       all_assemblies = new Dictionary<Assembly, ImportedAssemblyDefinition> ();
-               }
-
-               public List<ImportedAssemblyDefinition> Assemblies {
-                   get { return referenced_assemblies; }
-               }
-
-               public Module [] Modules {
-                       get { return modules; }
-               }
-
-               public void AddAssemblyReference (Assembly assembly)
-               {
-                       if (!all_assemblies.ContainsKey (assembly))
-                               AddAssemblyReference (CreateAssemblyDefinition (assembly));
-               }
-
-               public void AddModuleReference (Module m)
-               {
-                       int top = modules != null ? modules.Length : 0;
-                       Module [] n = new Module [top + 1];
-                       if (modules != null)
-                               modules.CopyTo (n, 0);
-                       n [top] = m;
-                       modules = n;
-
-                       if (m == RootContext.ToplevelTypes.Builder)
-                               return;
-
-                       foreach (var t in m.GetTypes ())
-                               RegisterNamespace (t.Namespace);
-               }
-
-               public ImportedAssemblyDefinition CreateAssemblyDefinition (Assembly assembly)
-               {
-                       ImportedAssemblyDefinition a;
-                       if (!all_assemblies.TryGetValue (assembly, out a)) {
-                               a = new ImportedAssemblyDefinition (assembly);
-                               all_assemblies.Add (assembly, a);
-                       }
-
-                       return a;
-               }
-
-               public void ComputeNamespaces (CompilerContext ctx)
-               {
-                       foreach (RootNamespace rn in root_namespaces.Values) {
-                               rn.ImportTypes (ctx);
-                       }
-               }
-
-               public void DefineRootNamespace (string alias, Assembly assembly, CompilerContext ctx)
-               {
-                       if (alias == alias_name) {
-                               NamespaceEntry.Error_GlobalNamespaceRedefined (Location.Null, ctx.Report);
-                               return;
-                       }
-
-                       RootNamespace retval = GetRootNamespace (alias);
-                       if (retval == null) {
-                               retval = new RootNamespace (alias);
-                               root_namespaces.Add (alias, retval);
-                       }
-
-                       retval.AddAssemblyReference (CreateAssemblyDefinition (assembly));
                }
 
                public override void Error_NamespaceDoesNotExist (Location loc, string name, int arity, IMemberContext ctx)
@@ -158,27 +71,6 @@ namespace Mono.CSharp {
                                "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
                                name);
                }
-
-               public RootNamespace GetRootNamespace (string name)
-               {
-                       RootNamespace rn;
-                       if (!root_namespaces.TryGetValue (name, out rn))
-                               return null;
-
-                       return rn;
-               }
-
-               public override void ImportTypes (CompilerContext ctx)
-               {
-                       base.ImportTypes (ctx);
-
-                       if (modules != null) {
-                               // 0 is this module
-                               for (int i = 1; i < modules.Length; ++i) {
-                                       ctx.MetaImporter.ImportModule (modules[i], this);
-                               }
-                       }
-               }
        }
 
        /// <summary>
@@ -713,7 +605,7 @@ namespace Mono.CSharp {
 
                        public virtual FullNamedExpression Resolve (IMemberContext rc, bool local)
                        {
-                               FullNamedExpression fne = rc.Compiler.GlobalRootNamespace.GetRootNamespace (Alias);
+                               FullNamedExpression fne = rc.CurrentMemberDefinition.Module.GetRootNamespace (Alias);
                                if (fne == null) {
                                        rc.Compiler.Report.Error (430, Location,
                                                "The extern alias `{0}' was not specified in -reference option",
@@ -781,7 +673,7 @@ namespace Mono.CSharp {
                public readonly DeclSpace SlaveDeclSpace;
                static readonly Namespace [] empty_namespaces = new Namespace [0];
                Namespace [] namespace_using_table;
-               CompilerContext ctx;
+               ModuleContainer ctx;
 
                static List<NamespaceEntry> entries = new List<NamespaceEntry> ();
 
@@ -790,8 +682,7 @@ namespace Mono.CSharp {
                        entries = new List<NamespaceEntry> ();
                }
 
-               // TODO: ctx should be a module
-               public NamespaceEntry (CompilerContext ctx, NamespaceEntry parent, CompilationUnit file, string name)
+               public NamespaceEntry (ModuleContainer ctx, NamespaceEntry parent, CompilationUnit file, string name)
                {
                        this.ctx = ctx;
                        this.parent = parent;
@@ -801,13 +692,14 @@ namespace Mono.CSharp {
                        if (parent != null)
                                ns = parent.NS.GetNamespace (name, true);
                        else if (name != null)
-                               ns = Compiler.GlobalRootNamespace.GetNamespace (name, true);
+                               ns = ctx.GlobalRootNamespace.GetNamespace (name, true);
                        else
-                               ns = Compiler.GlobalRootNamespace;
+                               ns = ctx.GlobalRootNamespace;
+
                        SlaveDeclSpace = new RootDeclSpace (this);
                }
 
-               private NamespaceEntry (CompilerContext ctx, NamespaceEntry parent, CompilationUnit file, Namespace ns, bool slave)
+               private NamespaceEntry (ModuleContainer ctx, NamespaceEntry parent, CompilationUnit file, Namespace ns, bool slave)
                {
                        this.ctx = ctx;
                        this.parent = parent;
@@ -1233,7 +1125,7 @@ namespace Mono.CSharp {
 
                public static void Error_GlobalNamespaceRedefined (Location loc, Report Report)
                {
-                       Report.Error (1681, loc, "You cannot redefine the global extern alias");
+                       Report.Error (1681, loc, "The global extern alias cannot be redefined");
                }
 
                public static void Error_NamespaceNotFound (Location loc, string name, Report Report)
@@ -1304,7 +1196,7 @@ namespace Mono.CSharp {
                #region IMemberContext Members
 
                public CompilerContext Compiler {
-                       get { return ctx; }
+                       get { return ctx.Compiler; }
                }
 
                public TypeSpec CurrentType {
index 98e868694cbc964ee389c24d48a6bcab7cfc2fcc..b96edd3cafda0ba63c2f66f8d7aca12801687075 100644 (file)
@@ -607,7 +607,7 @@ namespace Mono.CSharp {
                                Constant c = default_expr as Constant;
                                if (c != null) {
                                        if (default_expr.Type == TypeManager.decimal_type) {
-                                               builder.SetCustomAttribute (Const.CreateDecimalConstantAttribute (c, pa));
+                                               pa.DecimalConstant.EmitAttribute (builder, (decimal) c.GetValue (), c.Location);
                                        } else {
                                                builder.SetConstant (c.GetTypedValue ());
                                        }
index faa9b29f3665659c7a8fc718a20ff7dddf5686d7..42396e531702a21c079c30592e0cade94efddb0e 100644 (file)
@@ -32,6 +32,8 @@ namespace Mono.CSharp
 
                AssemblyDefinition assembly;
                readonly CompilerContext context;
+               readonly RootNamespace global_ns;
+               Dictionary<string, RootNamespace> alias_ns;
 
                ModuleBuilder builder;
                int static_data_counter;
@@ -53,6 +55,11 @@ namespace Mono.CSharp
 
                        types = new List<TypeContainer> ();
                        anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
+                       global_ns = new GlobalRootNamespace ();
+                       alias_ns = new Dictionary<string, RootNamespace> ();
+
+                       // TODO: REMOVE
+                       context.GlobalRootNamespace = global_ns;
                }
 
                #region Properties
@@ -108,6 +115,15 @@ namespace Mono.CSharp
                        }
                }
 
+               //
+               // Returns module global:: namespace
+               //
+               public RootNamespace GlobalRootNamespace {
+                   get {
+                       return global_ns;
+                   }
+               }
+
                public override ModuleContainer Module {
                        get {
                                return this;
@@ -206,10 +222,32 @@ namespace Mono.CSharp
                        return builder.DefineType (name, attr, null, typeSize);
                }
 
+               //
+               // Creates alias global namespace
+               //
+               public RootNamespace CreateRootNamespace (string alias)
+               {
+                       if (alias == global_ns.Alias) {
+                               NamespaceEntry.Error_GlobalNamespaceRedefined (Location.Null, Report);
+                               return global_ns;
+                       }
+
+                       RootNamespace rn;
+                       if (!alias_ns.TryGetValue (alias, out rn)) {
+                               rn = new RootNamespace (alias);
+                               alias_ns.Add (alias, rn);
+                       }
+
+                       return rn;
+               }
+
                public new void Define ()
                {
                        builder = assembly.CreateModuleBuilder ();
 
+                       // FIXME: Temporary hack for repl to reset
+                       TypeBuilder = null;
+
                        ResolveGlobalAttributes ();
 
                        foreach (TypeContainer tc in types)
@@ -236,12 +274,9 @@ namespace Mono.CSharp
                                OptAttributes.Emit ();
 
                        if (RootContext.Unsafe) {
-                               TypeSpec t = TypeManager.CoreLookupType (context, "System.Security", "UnverifiableCodeAttribute", MemberKind.Class, true);
-                               if (t != null) {
-                                       var unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, TypeSpec.EmptyTypes);
-                                       if (unverifiable_code_ctor != null)
-                                               builder.SetCustomAttribute (new CustomAttributeBuilder ((ConstructorInfo) unverifiable_code_ctor.GetMetaInfo (), new object[0]));
-                               }
+                               var pa = Compiler.PredefinedAttributes.UnverifiableCode;
+                               if (pa.IsDefined)
+                                       pa.EmitAttribute (builder);
                        }
 
                        foreach (var tc in types)
@@ -283,6 +318,13 @@ namespace Mono.CSharp
                        return null;
                }
 
+               public RootNamespace GetRootNamespace (string name)
+               {
+                       RootNamespace rn;
+                       alias_ns.TryGetValue (name, out rn);
+                       return rn;
+               }
+
                public override string GetSignatureForError ()
                {
                        return "<module>";
@@ -394,7 +436,7 @@ namespace Mono.CSharp
                /// <summary>
                /// It is called very early therefore can resolve only predefined attributes
                /// </summary>
-               public void ResolveGlobalAttributes ()
+               void ResolveGlobalAttributes ()
                {
                        if (OptAttributes == null)
                                return;
index a5c2618c4c4757b76aff638958eb6515ee6e1c34..7c38fb490827d6cb9df9122052ad94baedfc821e 100644 (file)
@@ -352,15 +352,16 @@ namespace Mono.CSharp {
        ///   population of the type has happened (for example, to
        ///   bootstrap the corlib.dll
        /// </remarks>
-       public static bool InitCoreTypes (CompilerContext ctx, IList<PredefinedTypeSpec> predefined)
+       public static bool InitCoreTypes (ModuleContainer module, IList<PredefinedTypeSpec> predefined)
        {
+               var ctx = module.Compiler;
                foreach (var p in predefined) {
                        var found = CoreLookupType (ctx, p.Namespace, p.Name, p.Kind, true);
                        if (found == null || found == p)
                                continue;
 
                        if (!RootContext.StdLib) {
-                               var ns = ctx.GlobalRootNamespace.GetNamespace (p.Namespace, false);
+                               var ns = module.GlobalRootNamespace.GetNamespace (p.Namespace, false);
                                ns.ReplaceTypeWithPredefined (found, p);
 
                                var tc = found.MemberDefinition as TypeContainer;
index 65563c460aed3e195785a7af3008a252790ea083..918284152dd5f2c45ee5dd02322af6f57911514f 100644 (file)
@@ -10,13 +10,10 @@ gtest-230.cs
 gtest-437.cs
 
 test-106.cs bug #628662
-test-416.cs bug #504085
 test-418.cs bug #504085
 test-454.cs bug #593342
 test-682.cs bug #530861
-test-704.cs IGNORE #472845
-test-715.cs bug #504085
-test-759.cs IGNORE bug #604218
+test-704.cs bug #472845
 
 test-xml-030.cs
 test-xml-035.cs
index 65563c460aed3e195785a7af3008a252790ea083..918284152dd5f2c45ee5dd02322af6f57911514f 100644 (file)
@@ -10,13 +10,10 @@ gtest-230.cs
 gtest-437.cs
 
 test-106.cs bug #628662
-test-416.cs bug #504085
 test-418.cs bug #504085
 test-454.cs bug #593342
 test-682.cs bug #530861
-test-704.cs IGNORE #472845
-test-715.cs bug #504085
-test-759.cs IGNORE bug #604218
+test-704.cs bug #472845
 
 test-xml-030.cs
 test-xml-035.cs
index bd77786bd2628b78d20eff29eae7dc6012bea63f..423d2e215b43ad9011dcbb4b69855d797f0229dd 100644 (file)
       </method>
     </type>
   </test>
+  <test name="dtest-friend-01.cs">
+    <type name="C">
+      <method name="Void Main()">
+        <size>90</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="dtest-implicitarray-01.cs">
     <type name="C">
       <method name="Void Method()">
       </method>
     </type>
   </test>
+  <test name="gtest-549.cs">
+    <type name="C`1[T]">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D+Impl">
+      <method name="Void MA(Int32)">
+        <size>1</size>
+      </method>
+      <method name="Void MB(Int32)">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Test">
+      <method name="Void Main()">
+        <size>21</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-1.cs">
     <type name="X">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-anon-20.cs">
+    <type name="C`1[T]">
+      <method name="Void Foo[U](U)">
+        <size>20</size>
+      </method>
+      <method name="Void Run()">
+        <size>1</size>
+      </method>
+      <method name="Void &lt;Foo`1&gt;m__0[U]()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="A">
+      <method name="Void Main()">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-21.cs">
     <type name="BaseObject">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-anon-64.cs">
+    <type name="C`1[T]">
+      <method name="Void Foo[U](U)">
+        <size>81</size>
+      </method>
+      <method name="Void Run(T)">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="E">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="A">
+      <method name="Int32 Main()">
+        <size>12</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C`1+&lt;Foo&gt;c__AnonStorey0`1[T,U]">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C`1+&lt;Foo&gt;c__AnonStorey1`1[T,U]">
+      <method name="U &lt;&gt;m__0()">
+        <size>12</size>
+      </method>
+      <method name="Void &lt;&gt;m__1()">
+        <size>12</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-7.cs">
     <type name="MyDisposable">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-iter-17.cs">
+    <type name="Test">
+      <method name="IEnumerable`1 TestMethod()">
+        <size>16</size>
+      </method>
+      <method name="Void Main()">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Test+&lt;TestMethod&gt;c__Iterator0">
+      <method name="Int32 System.Collections.Generic.IEnumerator&lt;int&gt;.get_Current()">
+        <size>7</size>
+      </method>
+      <method name="System.Object System.Collections.IEnumerator.get_Current()">
+        <size>12</size>
+      </method>
+      <method name="IEnumerator System.Collections.IEnumerable.GetEnumerator()">
+        <size>7</size>
+      </method>
+      <method name="IEnumerator`1 System.Collections.Generic.IEnumerable&lt;int&gt;.GetEnumerator()">
+        <size>26</size>
+      </method>
+      <method name="Boolean MoveNext()">
+        <size>45</size>
+      </method>
+      <method name="Void Dispose()">
+        <size>8</size>
+      </method>
+      <method name="Void Reset()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-iter-18.cs">
+    <type name="c">
+      <method name="IEnumerable`1 func()">
+        <size>16</size>
+      </method>
+      <method name="Void Main()">
+        <size>53</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="c+&lt;func&gt;c__Iterator0">
+      <method name="Char System.Collections.Generic.IEnumerator&lt;char&gt;.get_Current()">
+        <size>7</size>
+      </method>
+      <method name="System.Object System.Collections.IEnumerator.get_Current()">
+        <size>12</size>
+      </method>
+      <method name="IEnumerator System.Collections.IEnumerable.GetEnumerator()">
+        <size>7</size>
+      </method>
+      <method name="IEnumerator`1 System.Collections.Generic.IEnumerable&lt;char&gt;.GetEnumerator()">
+        <size>26</size>
+      </method>
+      <method name="Boolean MoveNext()">
+        <size>69</size>
+      </method>
+      <method name="Void Dispose()">
+        <size>8</size>
+      </method>
+      <method name="Void Reset()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-lambda-01.cs">
     <type name="X">
       <method name="Int32 Main()">
       </method>
     </type>
   </test>
+  <test name="test-416.cs">
+    <type name="ModTest">
+      <method name="Void Main(System.String[])">
+        <size>20</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="n1.Adder">
+      <method name="Int32 Add(Int32, Int32)">
+        <size>4</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-417.cs">
     <type name="blah2.MyClass">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="test-715.cs">
+    <type name="C">
+      <method name="Int32 Main()">
+        <size>2</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-716.cs">
     <type name="SS">
       <method name="Void .cctor()">
index 4720d6e2d76a517386aaa48f7990abfc136bd8bd..506c0bbb6527cf6723c6b050c7754593cc7d0874 100644 (file)
       </method>
     </type>
   </test>
+  <test name="gtest-549.cs">
+    <type name="C`1[T]">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D+Impl">
+      <method name="Void MA(Int32)">
+        <size>1</size>
+      </method>
+      <method name="Void MB(Int32)">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Test">
+      <method name="Void Main()">
+        <size>21</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-1.cs">
     <type name="X">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-anon-20.cs">
+    <type name="C`1[T]">
+      <method name="Void Foo[U](U)">
+        <size>20</size>
+      </method>
+      <method name="Void Run()">
+        <size>1</size>
+      </method>
+      <method name="Void &lt;Foo`1&gt;m__0[U]()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="A">
+      <method name="Void Main()">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-21.cs">
     <type name="BaseObject">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-anon-64.cs">
+    <type name="C`1[T]">
+      <method name="Void Foo[U](U)">
+        <size>81</size>
+      </method>
+      <method name="Void Run(T)">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="D">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="E">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="A">
+      <method name="Int32 Main()">
+        <size>12</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C`1+&lt;Foo&gt;c__AnonStorey0`1[T,U]">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C`1+&lt;Foo&gt;c__AnonStorey1`1[T,U]">
+      <method name="U &lt;&gt;m__0()">
+        <size>12</size>
+      </method>
+      <method name="Void &lt;&gt;m__1()">
+        <size>12</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anon-7.cs">
     <type name="MyDisposable">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-iter-17.cs">
+    <type name="Test">
+      <method name="IEnumerable`1 TestMethod()">
+        <size>16</size>
+      </method>
+      <method name="Void Main()">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Test+&lt;TestMethod&gt;c__Iterator0">
+      <method name="Int32 System.Collections.Generic.IEnumerator&lt;int&gt;.get_Current()">
+        <size>7</size>
+      </method>
+      <method name="System.Object System.Collections.IEnumerator.get_Current()">
+        <size>12</size>
+      </method>
+      <method name="IEnumerator System.Collections.IEnumerable.GetEnumerator()">
+        <size>7</size>
+      </method>
+      <method name="IEnumerator`1 System.Collections.Generic.IEnumerable&lt;int&gt;.GetEnumerator()">
+        <size>26</size>
+      </method>
+      <method name="Boolean MoveNext()">
+        <size>45</size>
+      </method>
+      <method name="Void Dispose()">
+        <size>8</size>
+      </method>
+      <method name="Void Reset()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-iter-18.cs">
+    <type name="c">
+      <method name="IEnumerable`1 func()">
+        <size>16</size>
+      </method>
+      <method name="Void Main()">
+        <size>53</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="c+&lt;func&gt;c__Iterator0">
+      <method name="Char System.Collections.Generic.IEnumerator&lt;char&gt;.get_Current()">
+        <size>7</size>
+      </method>
+      <method name="System.Object System.Collections.IEnumerator.get_Current()">
+        <size>12</size>
+      </method>
+      <method name="IEnumerator System.Collections.IEnumerable.GetEnumerator()">
+        <size>7</size>
+      </method>
+      <method name="IEnumerator`1 System.Collections.Generic.IEnumerable&lt;char&gt;.GetEnumerator()">
+        <size>26</size>
+      </method>
+      <method name="Boolean MoveNext()">
+        <size>69</size>
+      </method>
+      <method name="Void Dispose()">
+        <size>8</size>
+      </method>
+      <method name="Void Reset()">
+        <size>6</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-lambda-01.cs">
     <type name="X">
       <method name="Int32 Main()">
       </method>
     </type>
   </test>
+  <test name="test-416.cs">
+    <type name="ModTest">
+      <method name="Void Main(System.String[])">
+        <size>20</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="n1.Adder">
+      <method name="Int32 Add(Int32, Int32)">
+        <size>4</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-417.cs">
     <type name="blah2.MyClass">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="test-715.cs">
+    <type name="C">
+      <method name="Int32 Main()">
+        <size>2</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-716.cs">
     <type name="SS">
       <method name="Void .cctor()">
       </method>
     </type>
   </test>
+  <test name="test-759.cs">
+    <type name="B">
+      <method name="Void Main()">
+        <size>12</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-76.cs">
     <type name="foo">
       <method name="Void .ctor()">