2006-02-16 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Thu, 16 Feb 2006 00:24:15 +0000 (00:24 -0000)
committerMartin Baulig <martin@novell.com>
Thu, 16 Feb 2006 00:24:15 +0000 (00:24 -0000)
* generic.cs
(TypeManager.GetGenericFieldDefinition): New public method; use it
instead of the `FieldInfo.Mono_GetGenericFieldDefinition()' icall.

svn path=/trunk/mcs/; revision=56905

mcs/gmcs/ChangeLog
mcs/gmcs/ecore.cs
mcs/gmcs/generic.cs
mcs/gmcs/typemanager.cs

index cc9f1a33c0d9327a8ba62abd5a7aa00ada47e55c..baf574015f33c123e479f048af79d7cfb9f7e057 100644 (file)
@@ -1,3 +1,9 @@
+2006-02-16  Martin Baulig  <martin@ximian.com>
+
+       * generic.cs
+       (TypeManager.GetGenericFieldDefinition): New public method; use it
+       instead of the `FieldInfo.Mono_GetGenericFieldDefinition()' icall.
+
 2006-02-14  Martin Baulig  <martin@ximian.com>
 
        * *.cs: Use `Type.IsGenericType' instead of `Type.IsGenericInstance'.
index 8adafe8cfb998868e2d4aa39fb881b8c9b0ef80f..14a25c981376bf065ee35c7f8fca229ed25c95f3 100644 (file)
@@ -2994,7 +2994,7 @@ namespace Mono.CSharp {
                public override Expression ResolveMemberAccess (EmitContext ec, Expression left, Location loc,
                                                                SimpleName original)
                {
-                       FieldInfo fi = FieldInfo.Mono_GetGenericFieldDefinition ();
+                       FieldInfo fi = TypeManager.GetGenericFieldDefinition (FieldInfo);
 
                        Type t = fi.FieldType;
 
@@ -3244,16 +3244,13 @@ namespace Mono.CSharp {
                        ILGenerator ig = ec.ig;
                        bool is_volatile = false;
 
-                       FieldInfo the_fi = FieldInfo.Mono_GetGenericFieldDefinition ();
-                       if (the_fi is FieldBuilder){
-                               FieldBase f = TypeManager.GetField (the_fi);
-                               if (f != null){
-                                       if ((f.ModFlags & Modifiers.VOLATILE) != 0)
-                                               is_volatile = true;
-                                       
-                                       f.SetMemberIsUsed ();
-                               }
-                       } 
+                       FieldBase f = TypeManager.GetField (FieldInfo);
+                       if (f != null){
+                               if ((f.ModFlags & Modifiers.VOLATILE) != 0)
+                                       is_volatile = true;
+
+                               f.SetMemberIsUsed ();
+                       }
                        
                        if (FieldInfo.IsStatic){
                                if (is_volatile)
index b326cbdff75cfc8fba30eeea1e57bccd48d25989..b40828e742acf7fe650da0f0276c8bee2cfd0d89 100644 (file)
@@ -2059,6 +2059,23 @@ namespace Mono.CSharp {
                        return m;
                }
 
+               public static FieldInfo GetGenericFieldDefinition (FieldInfo fi)
+               {
+                       if (fi.DeclaringType.IsGenericTypeDefinition ||
+                           !fi.DeclaringType.IsGenericType)
+                               return fi;
+
+                       Type t = fi.DeclaringType.GetGenericTypeDefinition ();
+                       BindingFlags bf = BindingFlags.Public | BindingFlags.NonPublic |
+                               BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
+
+                       foreach (FieldInfo f in t.GetFields (bf))
+                               if (f.MetadataToken == fi.MetadataToken)
+                                       return f;
+
+                       return fi;
+               }
+
                //
                // Whether `array' is an array of T and `enumerator' is `IEnumerable<T>'.
                // For instance "string[]" -> "IEnumerable<string>".
index bf64ce6cda97dcf9fbf897841ecbc9df77388772..dfe9677a7b4fae40dfcc5c41382ff919378ac4cb 100644 (file)
@@ -1862,9 +1862,7 @@ public partial class TypeManager {
        //
        static public FieldBase GetField (FieldInfo fb)
        {
-               if (fb.DeclaringType.IsGenericType)
-                       fb = fb.Mono_GetGenericFieldDefinition ();
-
+               fb = GetGenericFieldDefinition (fb);
                return (FieldBase) fieldbuilders_to_fields [fb];
        }