Skip to content

Commit 6cfbe45

Browse files
committed
Create QuotePrinter
1 parent f7fc6fa commit 6cfbe45

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package dotty.tools.dotc
22
package decompiler
33

4-
import java.io.PrintStream
5-
64
import dotty.tools.dotc.core.Contexts._
75
import dotty.tools.dotc.core.Phases.Phase
86
import dotty.tools.dotc.core.tasty.TastyPrinter
@@ -11,7 +9,7 @@ import dotty.tools.dotc.core.tasty.TastyPrinter
119
*
1210
* @author Nicolas Stucki
1311
*/
14-
class DecompilationPrinter(out: PrintStream, codeOnly: Boolean) extends Phase {
12+
class DecompilationPrinter extends Phase {
1513

1614
override def phaseName: String = "decompilationPrinter"
1715

@@ -23,21 +21,16 @@ class DecompilationPrinter(out: PrintStream, codeOnly: Boolean) extends Phase {
2321
val doubleLine = "=" * pageWidth
2422
val line = "-" * pageWidth
2523

26-
if (!codeOnly) {
27-
out.println(doubleLine)
28-
out.println(unit.source)
29-
out.println(line)
30-
}
24+
println(doubleLine)
25+
println(unit.source)
26+
println(line)
3127

32-
out.print(unit.tpdTree.show)
28+
println(unit.tpdTree.show)
29+
println(line)
3330

34-
if (!codeOnly) {
35-
out.println()
36-
out.println(line)
37-
if (ctx.settings.printTasty.value) {
38-
new TastyPrinter(unit.pickled.head._2).printContents()
39-
out.println(line)
40-
}
31+
if (ctx.settings.printTasty.value) {
32+
new TastyPrinter(unit.pickled.head._2).printContents()
33+
println(line)
4134
}
4235
}
4336
}

compiler/src/dotty/tools/dotc/decompiler/TASTYDecompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import dotty.tools.dotc.core.Phases.Phase
1313
class TASTYDecompiler(out: PrintStream) extends TASTYCompiler {
1414
override def phases: List[List[Phase]] = List(
1515
List(new ReadTastyTreesFromClasses), // Load classes from tasty
16-
List(new DecompilationPrinter(out, codeOnly = false)) // Print all loaded classes
16+
List(new DecompilationPrinter) // Print all loaded classes
1717
)
1818
}

compiler/src/dotty/tools/dotc/quoted/ExprDecompiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package dotty.tools.dotc.quoted
33
import java.io.PrintStream
44

55
import dotty.tools.dotc.core.Phases.Phase
6-
import dotty.tools.dotc.decompiler.DecompilationPrinter
76

87
class ExprDecompiler(out: PrintStream) extends ExprCompiler(null) {
98
override def phases: List[List[Phase]] = List(
109
List(new ExprFrontend(putInClass = false)), // Create class from Expr
11-
List(new DecompilationPrinter(out, codeOnly = true)) // Print all loaded classes
10+
List(new QuotePrinter(out)) // Print all loaded classes
1211
)
1312
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dotty.tools.dotc.quoted
2+
3+
import java.io.PrintStream
4+
5+
import dotty.tools.dotc.core.Contexts._
6+
import dotty.tools.dotc.core.Phases.Phase
7+
8+
class QuotePrinter(out: PrintStream) extends Phase {
9+
10+
override def phaseName: String = "quotePrinter"
11+
12+
override def run(implicit ctx: Context): Unit = {
13+
val unit = ctx.compilationUnit
14+
out.print(unit.tpdTree.show)
15+
}
16+
}

0 commit comments

Comments
 (0)