Skip to content

Commit dac2630

Browse files
committed
modified test case & make debug info cleaner
1 parent a528e91 commit dac2630

File tree

5 files changed

+110
-9
lines changed

5 files changed

+110
-9
lines changed

compiler/src/dotty/tools/backend/jvm/MethodNode1.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ public void setAttribtues(){
405405
}
406406
if (typeBHintList.size() != 0){
407407
this.invokeReturnTypeAttribute = new InvokeReturnType(typeBHintList.size(), typeBHintList);
408+
System.out.println("invokeReturnTypeAttribute: " + invokeReturnTypeAttribute);
408409
visitAttribute(invokeReturnTypeAttribute);
409410
}
410411
List<TypeHints.TypeAHint> typeAHintList = new ArrayList<>();
@@ -421,6 +422,7 @@ public void setAttribtues(){
421422
}
422423
if (typeAHintList.size() != 0){
423424
this.instructionTypeArgumentsAttribute = new InstructionTypeArguments(typeAHintList);
425+
System.out.println("instructionTypeArgumentsAttribute: " + instructionTypeArgumentsAttribute);
424426
visitAttribute(instructionTypeArgumentsAttribute);
425427
}
426428

compiler/src/dotty/tools/backend/jvm/attributes/InstructionTypeArguments.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,17 @@ public ByteVector write(ClassWriter cw, byte[] code, int codeLength, int maxStac
6565
public List<TypeHints.TypeAHint> getTypeArguments() {
6666
return typeArguments;
6767
}
68+
69+
@Override
70+
public String toString() {
71+
StringBuilder sb = new StringBuilder("InstructionTypeArguments{");
72+
for (TypeHints.TypeAHint typeHint : typeArguments) {
73+
sb.append(typeHint.toString()).append(", ");
74+
}
75+
if (!typeArguments.isEmpty()) {
76+
sb.setLength(sb.length() - 2);
77+
}
78+
sb.append("}");
79+
return sb.toString();
80+
}
6881
}

compiler/src/dotty/tools/backend/jvm/attributes/InvokeReturnType.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,17 @@ public ByteVector write(ClassWriter cw, byte[] code, int codeLength, int maxStac
7373
return bv;
7474
}
7575

76+
@Override
77+
public String toString() {
78+
StringBuilder sb = new StringBuilder("InvokeReturnType{");
79+
sb.append("typeList=[");
80+
for (TypeHints.TypeBHint typeBHint : typeList) {
81+
sb.append(typeBHint.toString()).append(", ");
82+
}
83+
if (!typeList.isEmpty()) {
84+
sb.setLength(sb.length() - 2);
85+
}
86+
sb.append("]}");
87+
return sb.toString();
88+
}
7689
}

compiler/src/dotty/tools/backend/jvm/attributes/TypeHints.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ public int getBytecodeOffset() {
8181
public List<TypeA> getTypeList() {
8282
return typeList;
8383
}
84+
85+
@Override
86+
public String toString() {
87+
StringBuilder sb = new StringBuilder("TypeAHint{");
88+
sb.append("bytecodeOffset=").append(bytecodeOffset);
89+
sb.append(", typeList=[");
90+
for (TypeA typeA : typeList) {
91+
sb.append(typeA.toString()).append(", ");
92+
}
93+
if (!typeList.isEmpty()) {
94+
sb.setLength(sb.length() - 2);
95+
}
96+
sb.append("]}");
97+
return sb.toString();
98+
}
8499
}
85100

86101
public static class TypeB {
@@ -138,5 +153,13 @@ public int getBytecodeOffset() {
138153
public TypeB getTypeB() {
139154
return typeB;
140155
}
156+
157+
@Override
158+
public String toString() {
159+
return "TypeBHint{" +
160+
"bytecodeOffset=" + bytecodeOffset +
161+
", typeB=" + typeB +
162+
'}';
163+
}
141164
}
142165
}

tests/GenericMethod.scala

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class GenericMethod {
1515
// @MethodParameterType: M0, M1
1616
// @MethodReturnType: M0
1717
def first[A, B](fst: A, snd: B): A = fst
18-
override def toString: String = "Printing GenericMethod"
1918
}
2019

2120
object testGenericMethod1{
@@ -24,18 +23,68 @@ object testGenericMethod1{
2423
val v = gm.identity[Int](42)
2524
println("identity[Int](42):" + v)
2625

27-
@main def main2(): Unit =
26+
@main def main2(): Unit =
27+
val v = gm.identity2(2.2)
28+
println("identity2(2.2):" + v)
29+
30+
@main def main3(): Unit =
2831
val v = gm.first[Double, Long](4.2, 42L)
29-
println("first[Double, Long](4.2, 42L)" + v)
30-
}
32+
println("first[Double, Long](4.2, 42L):" + v)
3133

32-
object testGenericMethod2{
33-
val gm = new GenericMethod
34-
@main def main(): Unit =
35-
val v = gm.first[Double, Long](4.2, 42L)
36-
println("first[Double, Long](4.2, 42L)" + v)
34+
@main def main4(): Unit =
35+
val v = gm.identity[Foo](new Foo(1))
36+
println("identity[Foo](new Foo(1)):" + v)
37+
38+
@main def main5(): Unit =
39+
val v = gm.passRef(new Foo(2))
40+
println("passRef(new Foo(2)):" + v)
41+
42+
@main def main6(): Unit =
43+
val v = gm.identity[java.lang.Integer](java.lang.Integer.valueOf(8))
44+
println("identity[java.lang.Integer](java.lang.Integer.valueOf(8)):" + v)
45+
46+
@main def main7(): Unit =
47+
val v = gm.identity2(java.lang.Integer.valueOf(87))
48+
println("identity2(java.lang.Integer.valueOf(87)):" + v)
49+
50+
@main def main8(): Unit =
51+
val v = gm.passInt(88)
52+
println("passInt(88):" + v)
53+
54+
def genericMethod1[A, B, C](a: A, b: B, c: C): Unit =
55+
val v1 = gm.identity[B](b)
56+
println("identity[B](b):" + v1)
57+
val v2 = gm.first[C, A](c, a)
58+
println("first[C, A](c, a):" + v2)
59+
60+
@main def main9(): Unit =
61+
genericMethod1[Int, Char, Double](1, 'a', 3.14)
62+
// prints:
63+
// identity[B](b): a
64+
// first[C, A](c, a): 3.14
65+
66+
@main def main10(): Unit =
67+
genericMethod1[Foo, Foo, Foo](new Foo(1), new Foo(2), new Foo(3))
68+
// prints:
69+
// identity[B](b): Printing Foo 2
70+
// first[C, A](c, a): Printing Foo 3
71+
72+
def genericMethod2[A, B, C](a: A, b: B, c: C): Unit =
73+
val v1 = gm.identity2(c)
74+
println("identity2(c):" + v1)
75+
76+
@main def main11(): Unit =
77+
genericMethod2[Int, Char, Double](1, 'a', 3.14)
78+
// prints:
79+
// identity2(c): 3.14
80+
81+
@main def main12(): Unit =
82+
genericMethod2[Foo, Foo, Foo](new Foo(1), new Foo(2), new Foo(3))
83+
// prints:
84+
// identity2(c): Printing Foo 3
3785
}
3886

87+
/*
3988
object testGenericMethod {
4089
@main def testGenericMethodMain(): Unit = {
4190
println("test1:")
@@ -198,6 +247,7 @@ object testGenericMethod {
198247
val v8 : Any = v7
199248
}
200249
}
250+
*/
201251

202252
class Foo(id: Int) {
203253
//arbitrary scala class

0 commit comments

Comments
 (0)