In mcs:
authorRaja R Harinath <harinath@hurrynot.org>
Mon, 9 May 2005 12:01:29 +0000 (12:01 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Mon, 9 May 2005 12:01:29 +0000 (12:01 -0000)
Fix #74852.
* decl.cs (MemberCache.AddMethods): Register override methods,
rather than non-override methods.
* typemanager.cs (RegisterOverride): New.
(IsOverride): Update.

In tests:
* Makefile (test-harness-run): Depend on $(TEST_HARNESS_EXTRAS).
* harness.mk: Substitute the current profile into the compiler
options where the string 'PROFILE' is used.
* test-377.cs, test-377-default-il.il, test-377-net_2_0-il.il:
New tests from #74852.

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

mcs/mcs/ChangeLog
mcs/mcs/decl.cs
mcs/mcs/typemanager.cs
mcs/tests/ChangeLog
mcs/tests/Makefile
mcs/tests/harness.mk
mcs/tests/test-377-default-il.il [new file with mode: 0644]
mcs/tests/test-377-net_2_0-il.il [new file with mode: 0644]
mcs/tests/test-377.cs [new file with mode: 0644]

index aadcd06a3392422e14676d7b14dfc12397662947..1488f5a269c08067b1741b385691b4f6d0502930 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-09  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #74852.
+       * decl.cs (MemberCache.AddMethods): Register override methods,
+       rather than non-override methods.
+       * typemanager.cs (RegisterOverride): New.
+       (IsOverride): Update.
+
 2005-05-09  Marek Safar  <marek.safar@seznam.cz>
 
        Fix #73105.
index 2078001d6d45474c0ee7ccb200c1502d6ab55834..76b5c35d7f30e1fc539381fe6e3114d7b53b6186 100644 (file)
@@ -1395,6 +1395,8 @@ namespace Mono.CSharp {
                        AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
                }
 
+               static ArrayList overrides = new ArrayList ();
+
                void AddMethods (BindingFlags bf, Type type)
                {
                        MethodBase [] members = type.GetMethods (bf);
@@ -1415,16 +1417,21 @@ namespace Mono.CSharp {
                                while (curr.IsVirtual && (curr.Attributes & MethodAttributes.NewSlot) == 0) {
                                        MethodInfo base_method = curr.GetBaseDefinition ();
 
-                                       if (base_method == curr) {
+                                       if (base_method == curr)
                                                // Not every virtual function needs to have a NewSlot flag.
-                                               TypeManager.RegisterNonOverride (base_method);
                                                break;
-                                       }
-                                       
+
+                                       overrides.Add (curr);
                                        list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
                                        curr = base_method;
                                }
 
+                               if (overrides.Count > 0) {
+                                       for (int i = 0; i < overrides.Count; ++i)
+                                               TypeManager.RegisterOverride ((MethodBase) overrides [i], curr);
+                                       overrides.Clear ();
+                               }
+
                                // Unfortunately, the elements returned by Type.GetMethods() aren't
                                // sorted so we need to do this check for every member.
                                BindingFlags new_bf = bf;
index 350b25b2b79ac0a1c1cc738f977e023ca6e3d18d..833cc0378603b0cdf3f15dc8bbabd37e43918ea0 100644 (file)
@@ -265,12 +265,9 @@ public class TypeManager {
        static Hashtable method_params;
 
        // <remarks>
-       //   It is not straightforward, using reflection, to determine if a method overrides another.
-       //   Oftentimes, a non-override is marked with both the 'virtual' and 'newslot' method attributes.
-       //   However, it's not always the case.  We use this table to store those non-override methods
-       //   that aren't so conveniently marked.
+       //  A hash table from override methods to their base virtual method.
        // <remarks>
-       static Hashtable method_non_override;
+       static Hashtable method_overrides;
 
        // <remarks>
        //  Keeps track of methods
@@ -412,7 +409,7 @@ public class TypeManager {
                builder_to_method = new PtrHashtable ();
                method_arguments = new PtrHashtable ();
                method_params = new PtrHashtable ();
-               method_non_override = new PtrHashtable ();
+               method_overrides = new PtrHashtable ();
                indexer_arguments = new PtrHashtable ();
                builder_to_ifaces = new PtrHashtable ();
                
@@ -1738,16 +1735,21 @@ public class TypeManager {
                return (ParameterData) pd;
        }
 
-       static public void RegisterNonOverride (MethodBase m)
+       static public void RegisterOverride (MethodBase override_method, MethodBase base_method)
        {
-               method_non_override [m] = m;
+               if (method_overrides.Contains (override_method)) {
+                       if (method_overrides [override_method] != base_method)
+                               throw new InternalErrorException ("Override mismatch: " + override_method);
+                       return;
+               }
+               method_overrides [override_method] = base_method;
        }
 
        static public bool IsOverride (MethodBase m)
        {
                return m.IsVirtual &&
                        (m.Attributes & MethodAttributes.NewSlot) == 0 &&
-                       !method_non_override.Contains (m);
+                       (m is MethodBuilder || method_overrides.Contains (m));
        }
 
        /// <summary>
index 75fadde258147146e8076416f3a0f43580a6c872..ed865502a153a8c7cb335fa2d52fd7a0136decbb 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-09  Raja R Harinath  <rharinath@novell.com>
+
+       * Makefile (test-harness-run): Depend on $(TEST_HARNESS_EXTRAS).
+       * harness.mk: Substitute the current profile into the compiler
+       options where the string 'PROFILE' is used.
+       * test-377.cs, test-377-default-il.il, test-377-net_2_0-il.il:
+       New tests from #74852.
+
 2005-05-06  Marek Safar <marek.safar@seznam.cz>
 
        * test-376.cs: New enum test.
index afdd733b6f40ca93edf44a33f74c6c06f1d909a9..f0987c4f7fea9d93fc1964b47c0b9ed1b235b9d1 100644 (file)
@@ -17,7 +17,8 @@ ifeq (default, $(PROFILE))
 # means we can use --options, yay.
 MCS = $(with_mono_path) $(INTERNAL_MCS)
 endif
-ILASM = $(with_mono_path) $(INTERNAL_ILASM)
+ilasm = $(topdir)/class/lib/net_1_1_bootstrap/ilasm.exe
+ILASM = MONO_PATH="$(topdir)/class/lib/net_1_1_bootstrap$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(ilasm)
 
 ifeq (net_2_0, $(PROFILE))
 BOOTSTRAP_MCS = MONO_PATH="$(topdir)/class/lib/net_2_0_bootstrap$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/net_2_0_bootstrap/mcs.exe
@@ -33,7 +34,7 @@ USE_MCS_FLAGS :=
 # He may also move some to TEST_EXCLUDE_net_2_0 if some of the merges are inappropriate for GMCS.
 #
 NEW_TEST_SOURCES_common = test-336 test-369 cls-test-6 test-294 \
-       test-372 test-375 test-376
+       test-372 test-375 test-376 test-377
 
 #
 # Please do _not_ add any tests here - all new tests should go into NEW_TEST_SOURCES_common
@@ -158,7 +159,7 @@ TEST_ORDERING = \
 # Some tests may require additional files to be available in the current directory.
 # To promote interoperability, we prefer that those files not be referred to with ../ or ..\\
 # To that end, we will copy those files to the test-harness directory, so that we can refer to simple filenames.
-TEST_HARNESS_EXTRAS = $(wildcard *.inc) test-74.cs test-353-2.cs test-361-2.cs
+TEST_HARNESS_EXTRAS = $(wildcard *.inc) test-74.cs test-353-2.cs test-361-2.cs test-377-$(PROFILE)-il.dll
 
 all-local install-local uninstall-local:
 
@@ -204,7 +205,7 @@ test-generics-2:
 
 clean-local:
        -rm -fr dir-*
-       -rm -f *.exe *.netmodule *.out *.pdb casts.cs
+       -rm -f *.exe *.dll *.netmodule *.out *.pdb casts.cs
 
 dist-local: dist-default
        rm -f $(distdir)/casts.cs
@@ -221,7 +222,7 @@ test-harness: xmldocdiff.exe
 
 exe_tests := $(filter %-exe, $(TEST_SOURCES))
 
-test-harness-run:
+test-harness-run: $(TEST_HARNESS_EXTRAS)
        @-rm -f $(TEST_TAG).log
        @-rm -fr dir-$(TEST_TAG)
        @mkdir dir-$(TEST_TAG)
@@ -263,3 +264,6 @@ xml-doc-tests := $(filter xml-%, $(TEST_SOURCES))
 
 xmldocdiff.exe:
        $(CSCOMPILE) xmldocdiff.cs
+
+%-il.dll: %-il.il
+       $(ILASM) /dll $<
index 312d6d4c0f41a43ed24cde97848aafe89a2e5a18..42f2b14fe04f1486ef0b24c8d67fbe4a5396f92d 100644 (file)
@@ -14,7 +14,7 @@ XMLDOCDIFF = $(TEST_RUNTIME) ../xmldocdiff.exe
 all-local $(STD_TARGETS:=-local):
 
 %.res:
-       @f=../$*.cs; options=`sed -n 's,^// Compiler options:,,p' $$f`; \
+       @f=../$*.cs; options=`sed -n 's,^// Compiler options:,,p' $$f | sed 's,PROFILE,$(PROFILE),g'`; \
        case $$options in *-t:library*) ext=dll ;; *-t:module*) ext=netmodule ;; *) ext=exe ;; esac; \
        testlogfile="$*.log" ; \
         echo '*** $(CSCOMPILE)' "$$options -out:$*.$$ext $$f" > $$testlogfile ; \
diff --git a/mcs/tests/test-377-default-il.il b/mcs/tests/test-377-default-il.il
new file mode 100644 (file)
index 0000000..a92bb2e
--- /dev/null
@@ -0,0 +1,26 @@
+.assembly extern mscorlib
+{
+  .ver 1:0:5000:0
+  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
+}
+.assembly 'test-377-default-il'
+{
+  .hash algorithm 0x00008004
+  .ver  0:0:0:0
+}
+.module 'test-377-default-il.dll' // GUID = {F4E03A1B-389D-4487-83FD-FFA830293B9D}
+
+
+  .class interface public auto ansi abstract beforefieldinit Foo
+       extends [mscorlib]System.Object
+  {
+    // method line 2
+    .method public virtual  abstract 
+           instance default void foo (int32)  cil managed 
+    {
+        // Method begins at RVA 0x0
+    } // end of method Foo::instance default void foo () 
+
+  } // end of class Foo
+
+
diff --git a/mcs/tests/test-377-net_2_0-il.il b/mcs/tests/test-377-net_2_0-il.il
new file mode 100644 (file)
index 0000000..8adee78
--- /dev/null
@@ -0,0 +1,26 @@
+.assembly extern mscorlib
+{
+  .ver 2:0:3600:0
+  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
+}
+.assembly 'test-377-net_2_0-il'
+{
+  .hash algorithm 0x00008004
+  .ver  0:0:0:0
+}
+.module 'test-377-net_2_0-il.dll' // GUID = {F4E03A1B-389D-4487-83FD-FFA830293B9D}
+
+
+  .class interface public auto ansi abstract beforefieldinit Foo
+       extends [mscorlib]System.Object
+  {
+    // method line 2
+    .method public virtual  abstract 
+           instance default void foo (int32)  cil managed 
+    {
+        // Method begins at RVA 0x0
+    } // end of method Foo::instance default void foo () 
+
+  } // end of class Foo
+
+
diff --git a/mcs/tests/test-377.cs b/mcs/tests/test-377.cs
new file mode 100644 (file)
index 0000000..9c4bd89
--- /dev/null
@@ -0,0 +1,12 @@
+// Compiler options: -t:library -r:test-377-PROFILE-il.dll
+
+using System;
+using System.Reflection;
+
+public class Tests {
+
+       public void test () {
+               Foo f = null;
+               f.foo (5);
+       }
+}