From df342cd649e966c9ff9b714b52335b17062609af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20=C5=BBarnowski?= Date: Wed, 6 Mar 2019 17:01:25 +0100 Subject: [PATCH] add dotty compiler class --- project/Build.scala | 2 ++ .../src/tasty4scalac/Compiler.scala | 1 + .../integration/src/tasty4scalac/Dotty.scala | 28 +++++++++++++++++++ .../test/tasty4scalac/CompilerTest.java | 3 +- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tasty4scalac/integration/src/tasty4scalac/Dotty.scala diff --git a/project/Build.scala b/project/Build.scala index ecd8fe58ecb5..7789e4c78d8d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -845,10 +845,12 @@ object Build { val scalacClasspath = toClasspath(scalaLibrary, scalaCompiler, scalaReflect) val pluginClasspath = toClasspath(pluginJar, dottyLibrary, dottyCompiler, dottyInterfaces) + val dottyClasspath = toClasspath(scalaLibrary, dottyLibrary, dottyCompiler, dottyInterfaces) Seq( "-Dscalac.classpath=" + scalacClasspath, "-Dscalac.plugin.classpath=" + pluginClasspath, + "-Ddotty.classpath=" + dottyClasspath, "-Dtest.root.directory=" + (baseDirectory.value / "test-resources") ) } diff --git a/tasty4scalac/integration/src/tasty4scalac/Compiler.scala b/tasty4scalac/integration/src/tasty4scalac/Compiler.scala index 5d6f2825d609..1994fbd319d6 100644 --- a/tasty4scalac/integration/src/tasty4scalac/Compiler.scala +++ b/tasty4scalac/integration/src/tasty4scalac/Compiler.scala @@ -8,6 +8,7 @@ trait Compiler { } object Compiler { + def dotty(): Compiler = Dotty() def scalac(): Compiler = Scalac() trait Factory { diff --git a/tasty4scalac/integration/src/tasty4scalac/Dotty.scala b/tasty4scalac/integration/src/tasty4scalac/Dotty.scala new file mode 100644 index 000000000000..9af5096eb7b3 --- /dev/null +++ b/tasty4scalac/integration/src/tasty4scalac/Dotty.scala @@ -0,0 +1,28 @@ +package tasty4scalac + +import dotty.tools.dotc.core.Comments.{ContextDoc, ContextDocstrings} +import dotty.tools.dotc.core.Contexts +import dotty.tools.dotc.core.Contexts.ContextBase +import dotty.tools.dotc.reporting.Reporter.NoReporter +import dotty.tools.io.VirtualDirectory +import tasty4scalac.Compiler.Factory + +final class Dotty(val ctx: Contexts.Context) extends dotty.tools.dotc.Compiler with Compiler { + override def compile(code: String): Unit = newRun(ctx.fresh).compile(code) +} + +object Dotty extends Factory { + private val classpath = System.getProperty("dotty.classpath") + + override def apply(): Compiler = { + implicit val ctx: Contexts.FreshContext = new ContextBase().initialCtx.fresh + ctx.setSetting(ctx.settings.classpath, classpath) + ctx.setSetting(ctx.settings.YtestPickler, true) + ctx.setSetting(ctx.settings.encoding, "UTF8") + ctx.setSetting(ctx.settings.outputDir, new VirtualDirectory("")) + + ctx.setReporter(NoReporter) + ctx.setProperty(ContextDoc, new ContextDocstrings) + new Dotty(ctx) + } +} \ No newline at end of file diff --git a/tasty4scalac/integration/test/tasty4scalac/CompilerTest.java b/tasty4scalac/integration/test/tasty4scalac/CompilerTest.java index 57c3bdb98405..54a3d8eaf457 100644 --- a/tasty4scalac/integration/test/tasty4scalac/CompilerTest.java +++ b/tasty4scalac/integration/test/tasty4scalac/CompilerTest.java @@ -18,7 +18,8 @@ public CompilerTest(Compiler factory) { @Parameterized.Parameters(name = "{index}: {0}") public static Collection parameters() { return Arrays.asList(new Compiler[][]{ - {Scalac$.MODULE$.apply()} + {Scalac$.MODULE$.apply()}, + {Dotty$.MODULE$.apply()} }); }