Skip to content

Commit f5bcd31

Browse files
committed
change method name 'post' to 'onSucceed', which is used in Java version
1 parent 01cd6f5 commit f5bcd31

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

src/main/scala/decaf/backend/asm/Asm.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Asm(val emitter: AsmEmitter, val regAlloc: RegAlloc) extends Phase[TacProg
4242
emitter.emitEnd()
4343
}
4444

45-
override def post(code: String)(implicit config: Config): Unit = {
45+
override def onSucceed(code: String)(implicit config: Config): Unit = {
4646
if (config.target.equals(Config.Target.PA5)) {
4747
val path = config.dstDir / config.sourceBaseName + ".s"
4848
val printer = new PrintWriter(path)

src/main/scala/decaf/backend/opt/Optimizer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Optimizer extends Phase[TacProg, TacProg]("optimizer") {
1414

1515
override def transform(input: TacProg): TacProg = input
1616

17-
override def post(program: TacProg)(implicit config: Config): Unit = {
17+
override def onSucceed(program: TacProg)(implicit config: Config): Unit = {
1818
if (config.target.equals(Config.Target.PA4)) { // First dump the tac program to file,
1919
val path = config.dstDir / config.sourceBaseName + ".tac"
2020
val printer = new PrintWriter(path)

src/main/scala/decaf/driver/Phase.scala

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,39 @@ import java.io.PrintStream
44

55
import decaf.driver.error.ErrorIssuer
66

7+
/**
8+
* Compilation of a Decaf program is processed phase-by-phase. Each phase transforms a kind of language representation
9+
* into another.
10+
*
11+
* @tparam In type of input
12+
* @tparam Out type of output
13+
* @param name phase name
14+
* @see [[decaf.driver.Tasks]]
15+
* @see [[ErrorIssuer]]
16+
*/
717
abstract class Phase[In, Out](val name: String) extends ErrorIssuer {
18+
/**
19+
* Entry of the actual transformation.
20+
*
21+
* @param input input
22+
* @return output
23+
*/
824
def transform(input: In): Out
925

10-
def post(output: Out)(implicit config: Config): Unit = {}
26+
/**
27+
* A phase is said to be ''successful'', if and only if no errors occur (i.e. `!hasError()`).
28+
* When a phase is successful, this method will be executed.
29+
*
30+
* @param output output of the transformation
31+
*/
32+
def onSucceed(output: Out)(implicit config: Config): Unit = {}
1133

34+
/**
35+
* Entry of the phase.
36+
*
37+
* @param input input
38+
* @return output (if succeeds)
39+
*/
1240
def apply(input: In)(implicit config: Config): Option[Out] = {
1341
val out = transform(input)
1442
if (hasError) {
@@ -18,7 +46,7 @@ abstract class Phase[In, Out](val name: String) extends ErrorIssuer {
1846
}
1947
None
2048
} else {
21-
post(out)
49+
onSucceed(out)
2250
Some(out)
2351
}
2452
}

src/main/scala/decaf/frontend/parsing/Parser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Parser extends Phase[InputStream, Tree]("parser") {
4949
* @param tree the syntax tree
5050
* @param config the compiler configuration
5151
*/
52-
override def post(tree: Tree)(implicit config: Config): Unit = {
52+
override def onSucceed(tree: Tree)(implicit config: Config): Unit = {
5353
if (config.target == Config.Target.PA1) { // pretty only when the target is PA1
5454
val printer = new PrettyTree(new IndentPrinter(config.output))
5555
printer.pretty(tree)

src/main/scala/decaf/frontend/tac/TacGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TacGen extends Phase[Tree, TacProg]("tacgen") with TacEmitter {
4646
pw.visitEnd()
4747
}
4848

49-
override def post(program: TacProg)(implicit config: Config): Unit = {
49+
override def onSucceed(program: TacProg)(implicit config: Config): Unit = {
5050
if (config.target.equals(Config.Target.PA3)) { // First dump the tac program to file,
5151
val path = config.dstDir / config.sourceBaseName + ".tac"
5252
val printer = new PrintWriter(path)

src/main/scala/decaf/frontend/typecheck/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Typer extends Phase[Tree, Tree]("typer") with Util {
8585
* @param tree the typed tree
8686
* @param config the compiler configuration
8787
*/
88-
override def post(tree: Tree)(implicit config: Config): Unit = {
88+
override def onSucceed(tree: Tree)(implicit config: Config): Unit = {
8989
if (config.target == Config.Target.PA2) {
9090
val printer = new PrettyScope(new IndentPrinter(config.output))
9191
printer.pretty(tree.scope)

src/main/scala/decaf/jvm/JVMGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class JVMGen extends Phase[Tree, List[JVMClass]]("jvm") with Util {
253253
mv.visitTypeInsn(Opcodes.CHECKCAST, internalName(clazz))
254254
}
255255

256-
override def post(output: List[JVMClass])(implicit config: Config): Unit = {
256+
override def onSucceed(output: List[JVMClass])(implicit config: Config): Unit = {
257257
if (config.target == Config.Target.PA3_JVM) {
258258
output.foreach { _.writeFile(config.dstDir) }
259259
}

0 commit comments

Comments
 (0)