Attached the same patch with coding style fixed.
Kornél Pál wrote:
Hi Marek,
Emit and close top level compiler generated classes as well.
They are already closed.
Most of the compiler generated classes are nested types and those are
closed.
On the other hand DynamicExpressionStatement.StaticDataClass in
dynamic.cs is a top level compiler generated class.
Currently it is closed by using
RootContext.RegisterCompilerGeneratedType that is very ugly hack because
that is closing the TypeBuilder rather than the compiler generated
class instance that skips the whole infrastructure.
In my opinion RootContext.RegisterCompilerGeneratedType is intended for
compiler generated TypeBuilders that have no higher level representation
that is not the case for compiler generated classes.
>> Don't make compiler generated classes sealed by default.
> What is benefit of not doing that?
This is also related to the same class because that was explicitly
removing the sealed modifier to enable the static modifier.
Although currently only a single compiler generated class benefits from
both of these modifications I don't see any drawbacks and in my opinion
the changes result in a more properly designed compiler generated class
infrastructure.
Kornél
Index: mcs/dynamic.cs
===================================================================
--- mcs/dynamic.cs (revision 152670)
+++ mcs/dynamic.cs (working copy)
@@ -202,7 +202,6 @@
new MemberName
(CompilerGeneratedClass.MakeName (null, "c", "DynamicSites", 0)),
Modifiers.INTERNAL | Modifiers.STATIC)
{
- ModFlags &= ~Modifiers.SEALED;
}
}
@@ -264,9 +263,6 @@
RootContext.ToplevelTypes.AddCompilerGeneratedClass (global_site_container);
global_site_container.DefineType ();
global_site_container.Define ();
-// global_site_container.EmitType ();
-
- RootContext.RegisterCompilerGeneratedType
(global_site_container.TypeBuilder);
}
return global_site_container;
Index: mcs/anonymous.cs
===================================================================
--- mcs/anonymous.cs (revision 152670)
+++ mcs/anonymous.cs (working copy)
@@ -25,7 +25,7 @@
}
protected CompilerGeneratedClass (DeclSpace parent, MemberName
name, Modifiers mod)
- : base (parent.NamespaceEntry, parent, name, mod |
Modifiers.COMPILER_GENERATED | Modifiers.SEALED, null)
+ : base (parent.NamespaceEntry, parent, name, mod |
Modifiers.COMPILER_GENERATED, null)
{
}
@@ -141,7 +141,7 @@
public LocalTemporary Instance;
public AnonymousMethodStorey (Block block, TypeContainer
parent, MemberBase host, GenericMethod generic, string name)
- : base (parent, generic, MakeMemberName (host, name,
generic, block.StartLocation), Modifiers.PRIVATE)
+ : base (parent, generic, MakeMemberName (host, name,
generic, block.StartLocation), Modifiers.PRIVATE | Modifiers.SEALED)
{
Parent = parent;
OriginalSourceBlock = block;
Index: mcs/support.cs
===================================================================
--- mcs/support.cs (revision 152670)
+++ mcs/support.cs (working copy)
@@ -17,6 +17,7 @@
using System.Reflection.Emit;
using System.Globalization;
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
namespace Mono.CSharp {
@@ -30,12 +31,12 @@
public bool Equals (T x, T y)
{
- return object.ReferenceEquals (x, y);
+ return (object) x == (object) y;
}
public int GetHashCode (T obj)
{
- return obj == null ? 0 : obj.GetHashCode ();
+ return RuntimeHelpers.GetHashCode (obj);
}
}
Index: mcs/rootcontext.cs
===================================================================
--- mcs/rootcontext.cs (revision 152670)
+++ mcs/rootcontext.cs (working copy)
@@ -267,6 +267,9 @@
foreach (Delegate d in root.Delegates)
d.CloseType ();
+ if (root.CompilerGeneratedClasses != null)
+ foreach (CompilerGeneratedClass c in
root.CompilerGeneratedClasses)
+ c.CloseType ();
//
// If we have a <PrivateImplementationDetails> class,
close it
@@ -373,6 +376,10 @@
d.Emit ();
}
+ if (root.CompilerGeneratedClasses != null)
+ foreach (CompilerGeneratedClass c in
root.CompilerGeneratedClasses)
+ c.EmitType ();
+
CodeGen.Assembly.Emit (root);
root.Emit ();
}
Index: mcs/class.cs
===================================================================
--- mcs/class.cs (revision 152670)
+++ mcs/class.cs (working copy)
@@ -583,7 +583,13 @@
return delegates;
}
}
-
+
+ public IList<CompilerGeneratedClass> CompilerGeneratedClasses {
+ get {
+ return compiler_generated;
+ }
+ }
+
protected override TypeAttributes TypeAttr {
get {
return ModifiersExtensions.TypeAttr (ModFlags,
IsTopLevel) | base.TypeAttr;
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list