@@ -3,9 +3,10 @@ package scala.tools.partest
3
3
import scala .tools .nsc .util .JavaClassPath
4
4
import scala .collection .JavaConverters ._
5
5
import scala .tools .asm
6
- import asm .ClassReader
6
+ import asm .{ ClassReader }
7
7
import asm .tree .{ClassNode , MethodNode , InsnList }
8
8
import java .io .InputStream
9
+ import AsmNode ._
9
10
10
11
/**
11
12
* Provides utilities for inspecting bytecode using ASM library.
@@ -29,21 +30,47 @@ import java.io.InputStream
29
30
*
30
31
*/
31
32
abstract class BytecodeTest extends ASMConverters {
33
+ import instructions ._
32
34
33
35
/** produce the output to be compared against a checkfile */
34
36
protected def show (): Unit
35
37
36
38
def main (args : Array [String ]): Unit = show
37
39
38
- // asserts
40
+ // asserts
39
41
def sameBytecode (methA : MethodNode , methB : MethodNode ) = {
40
42
val isa = instructions.fromMethod(methA)
41
43
val isb = instructions.fromMethod(methB)
42
44
if (isa == isb) println(" bytecode identical" )
43
45
else diffInstructions(isa, isb)
44
46
}
45
47
46
- import instructions ._
48
+ // Do these classes have all the same methods, with the same names, access,
49
+ // descriptors and generic signatures? Method bodies are not considered, and
50
+ // the names of the classes containing the methods are substituted so they do
51
+ // not appear as differences.
52
+ def sameMethodAndFieldSignatures (clazzA : ClassNode , clazzB : ClassNode ): Boolean = {
53
+ val ms1 = clazzA.fieldsAndMethods.toIndexedSeq
54
+ val ms2 = clazzB.fieldsAndMethods.toIndexedSeq
55
+ val name1 = clazzA.name
56
+ val name2 = clazzB.name
57
+
58
+ if (ms1.length != ms2.length) {
59
+ println(" Different member counts in $name1 and $name2" )
60
+ false
61
+ }
62
+ else (ms1, ms2).zipped forall { (m1, m2) =>
63
+ val c1 = m1.characteristics
64
+ val c2 = m2.characteristics.replaceAllLiterally(name2, name1)
65
+ if (c1 == c2)
66
+ println(s " [ok] $m1" )
67
+ else
68
+ println(s " [fail] \n in $name1: $c1\n in $name2: $c2" )
69
+
70
+ c1 == c2
71
+ }
72
+ }
73
+
47
74
// bytecode is equal modulo local variable numbering
48
75
def equalsModuloVar (a : Instruction , b : Instruction ) = (a, b) match {
49
76
case _ if a == b => true
0 commit comments