Skip to content

Commit

Permalink
Fixed instrumentation code so that it can deal with:
Browse files Browse the repository at this point in the history
1. leading imports: object sheet { import math; … }
2. trailing objects: object sheet { … } object other { … }

Review by @dragos
  • Loading branch information
odersky committed Sep 25, 2012
1 parent 6ba05fd commit 092eac7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/compiler/scala/tools/nsc/interactive/ScratchPadMaker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait ScratchPadMaker { self: Global =>

private def literal(str: String) = "\"\"\""+str+"\"\"\""

private val prologue = "import scala.runtime.WorksheetSupport._; def main(args: Array[String])=$execute{"
private val prologue = ";import scala.runtime.WorksheetSupport._; def main(args: Array[String])=$execute{"

private val epilogue = "}"

Expand Down Expand Up @@ -117,12 +117,13 @@ trait ScratchPadMaker { self: Global =>
super.traverse(tree)
case ModuleDef(_, name, Template(_, _, body)) =>
val topLevel = objectName.isEmpty
if (topLevel) objectName = tree.symbol.fullName
body foreach traverseStat
if (skipped != 0) { // don't issue prologue and epilogue if there are no instrumented statements
applyPendingPatches(skipped)
if (topLevel)
if (topLevel) {
objectName = tree.symbol.fullName
body foreach traverseStat
if (skipped != 0) { // don't issue prologue and epilogue if there are no instrumented statements
applyPendingPatches(skipped)
patches += Patch(skipped, epilogue)
}
}
case _ =>
}
Expand Down

0 comments on commit 092eac7

Please sign in to comment.