1
- package dotty .tools
1
+ package dotty
2
+ package tools
2
3
package backend .jvm
3
4
4
5
import dotc .core .Contexts .{Context , ContextBase }
6
+ import dotc .core .Comments .{ContextDoc , ContextDocstrings }
5
7
import dotc .core .Phases .Phase
6
8
import dotc .Compiler
7
9
@@ -11,19 +13,13 @@ import asm._
11
13
import asm .tree ._
12
14
import scala .collection .JavaConverters ._
13
15
14
- import io .JavaClassPath
16
+ import io .{ AbstractFile , JavaClassPath , VirtualDirectory }
15
17
import scala .collection .JavaConverters ._
16
18
import scala .tools .asm .{ClassWriter , ClassReader }
17
19
import scala .tools .asm .tree ._
18
20
import java .io .{File => JFile , InputStream }
19
21
20
- class TestGenBCode (val outDir : String ) extends GenBCode {
21
- override def phaseName : String = " testGenBCode"
22
- val virtualDir = new Directory (outDir, None )
23
- override def outputDir (implicit ctx : Context ) = virtualDir
24
- }
25
-
26
- trait DottyBytecodeTest extends DottyTest {
22
+ trait DottyBytecodeTest {
27
23
import AsmNode ._
28
24
import ASMConverters ._
29
25
@@ -45,32 +41,23 @@ trait DottyBytecodeTest extends DottyTest {
45
41
val javaString = " java/lang/String"
46
42
}
47
43
48
- private def bCodeCheckingComp (testPhase : TestGenBCode )(check : Directory => Unit ) = {
49
- class AssertionChecker extends Phase {
50
- def phaseName = " assertionChecker"
51
- def run (implicit ctx : Context ): Unit = check(testPhase.virtualDir)
52
- }
53
- new Compiler {
54
- override protected def backendPhases : List [List [Phase ]] =
55
- List (testPhase) ::
56
- List (new AssertionChecker ) ::
57
- Nil
58
- }
44
+ def initCtx = {
45
+ val ctx0 = (new ContextBase ).initialCtx.fresh
46
+ val outputDir = new VirtualDirectory (" <DottyBytecodeTest output>" )
47
+ ctx0.setSetting(ctx0.settings.classpath, Jars .dottyLib)
48
+ ctx0.setProperty(ContextDoc , new ContextDocstrings )
49
+ ctx0.setSetting(ctx0.settings.outputDir, outputDir)
59
50
}
60
51
61
- private def outPath (obj : Any ) =
62
- " /genBCodeTest" + math.abs(obj.hashCode) + System .currentTimeMillis
63
-
64
52
/** Checks source code from raw string */
65
- def checkBCode (source : String )(assertion : Directory => Unit ) = {
66
- val comp = bCodeCheckingComp(new TestGenBCode (outPath(source)))(assertion)
67
- comp.newRun.compile(source)
68
- }
53
+ def checkBCode (source : String )(checkOutput : AbstractFile => Unit ): Unit = {
54
+ implicit val ctx : Context = initCtx
55
+
56
+ val compiler = new Compiler
57
+ val run = compiler.newRun
58
+ compiler.newRun.compile(source)
69
59
70
- /** Checks actual _files_ referenced in `sources` list */
71
- def checkBCode (sources : List [String ])(assertion : Directory => Unit ) = {
72
- val comp = bCodeCheckingComp(new TestGenBCode (outPath(sources)))(assertion)
73
- comp.newRun.compile(sources)
60
+ checkOutput(ctx.settings.outputDir.value)
74
61
}
75
62
76
63
protected def loadClassNode (input : InputStream , skipDebugInfo : Boolean = true ): ClassNode = {
0 commit comments