Don't emit reaonly. prefix for reference loads
[mono.git] / mcs / mcs / roottypes.cs
index a5be3f835a4a8deb13bc5d30b4b26538c748666d..df7962043c9088089aa24c0c70a8e059e3384662 100644 (file)
@@ -63,27 +63,14 @@ namespace Mono.CSharp
                                        // DefineInitializedData because it creates public type,
                                        // and its name is not unique among modules
                                        //
-                                       size_type = new Struct (null, this, new MemberName ("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
+                                       size_type = new Struct (null, this, new MemberName ("$ArrayType=" + data.Length, loc), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
                                        size_type.CreateType ();
                                        size_type.DefineType ();
 
                                        size_types.Add (data.Length, size_type);
-                                       var ctor = Module.PredefinedMembers.StructLayoutAttributeCtor.Resolve (Location);
-                                       if (ctor != null) {
-                                               var argsEncoded = new AttributeEncoder ();
-                                               argsEncoded.Encode ((short) LayoutKind.Explicit);
-
-                                               var field_size = Module.PredefinedMembers.StructLayoutSize.Resolve (Location);
-                                               var pack = Module.PredefinedMembers.StructLayoutPack.Resolve (Location);
-                                               if (field_size != null && pack != null) {
-                                                       argsEncoded.EncodeNamedArguments (
-                                                               new[] { field_size, pack },
-                                                               new[] { new IntConstant (Compiler.BuiltinTypes, (int) data.Length, Location), new IntConstant (Compiler.BuiltinTypes, 1, Location) }
-                                                       );
-
-                                                       size_type.TypeBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), argsEncoded.ToArray ());
-                                               }
-                                       }
+
+                                       // It has to work even if StructLayoutAttribute does not exist
+                                       size_type.TypeBuilder.__SetLayout (1, data.Length);
                                }
 
                                var name = "$field-" + fields.ToString ("X");
@@ -401,7 +388,10 @@ namespace Mono.CSharp
                public new void CreateType ()
                {
                        // Release cache used by parser only
-                       defined_type_containers = null;
+                       if (Evaluator == null)
+                               defined_type_containers = null;
+                       else
+                               defined_type_containers.Clear ();
 
                        foreach (TypeContainer tc in types)
                                tc.CreateType ();
@@ -555,6 +545,7 @@ namespace Mono.CSharp
 
                protected override void RemoveMemberType (TypeContainer ds)
                {
+                       defined_type_containers.Remove (ds.MemberName);
                        ds.NamespaceEntry.NS.RemoveDeclSpace (ds.Basename);
                        base.RemoveMemberType (ds);
                }