Permalink
Browse files

Two fixes for the worksheet instrumenter

(1) Handle empty worksheets
(2) Handle for expressions

Review by @dragos
(cherry picked from commit 20dc9cd7848863097b07d1cb84ae3f729f7e94da)
  • Loading branch information...
1 parent e03a5b7 commit 32cb44f9136a03e762baba420c0be2f4c27f4354 @odersky odersky committed with dragos Aug 29, 2012
@@ -1366,7 +1366,8 @@ self =>
}
parseDo
case FOR =>
- def parseFor = atPos(in.skipToken()) {
+ val start = in.skipToken()
+ def parseFor = atPos(start) {
val enums =
if (in.token == LBRACE) inBracesOrNil(enumerators())
else inParensOrNil(enumerators())
@@ -1378,7 +1379,11 @@ self =>
makeFor(enums, expr())
}
}
- parseFor
+ def adjustStart(tree: Tree) =
+ if (tree.pos.isRange && start < tree.pos.start)
+ tree setPos tree.pos.withStart(start)
+ else tree
+ adjustStart(parseFor)
case RETURN =>
def parseReturn =
atPos(in.skipToken()) {
@@ -113,9 +113,11 @@ trait ScratchPadMaker { self: Global =>
val topLevel = objectName.isEmpty
if (topLevel) objectName = tree.symbol.fullName
body foreach traverseStat
- applyPendingPatches(skipped)
- if (topLevel)
- patches += Patch(skipped, epilogue)
+ if (skipped != 0) { // don't issue prologue and epilogue if there are no instrumented statements
+ applyPendingPatches(skipped)
+ if (topLevel)
+ patches += Patch(skipped, epilogue)
+ }
case _ =>
}

0 comments on commit 32cb44f

Please sign in to comment.