summaryrefslogtreecommitdiff
path: root/src/interactive
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-11-18 09:39:55 -0800
committerPaul Phillips <paulp@improving.org>2013-11-18 11:43:57 -0800
commit2d4f0f1859b957b744f9b9f222dec8e8c478a4a8 (patch)
treeca7f779bc12f4b23b91558ad5b871d1e895ed9ac /src/interactive
parentc243435f113615b2f7407fbd683c93ec16c73749 (diff)
downloadscala-2d4f0f1859b957b744f9b9f222dec8e8c478a4a8.tar.gz
scala-2d4f0f1859b957b744f9b9f222dec8e8c478a4a8.tar.bz2
scala-2d4f0f1859b957b744f9b9f222dec8e8c478a4a8.zip
Removing deprecated code.
Code which has been deprecated since 2.10.0 and which allowed for straightforward removal.
Diffstat (limited to 'src/interactive')
-rw-r--r--src/interactive/scala/tools/nsc/interactive/CompilerControl.scala37
-rw-r--r--src/interactive/scala/tools/nsc/interactive/Global.scala13
-rw-r--r--src/interactive/scala/tools/nsc/interactive/REPL.scala55
-rw-r--r--src/interactive/scala/tools/nsc/interactive/ScratchPadMaker.scala201
4 files changed, 0 insertions, 306 deletions
diff --git a/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala b/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala
index d036a6e853..69cae24808 100644
--- a/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala
+++ b/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala
@@ -62,17 +62,6 @@ trait CompilerControl { self: Global =>
def onUnitOf[T](source: SourceFile)(op: RichCompilationUnit => T): T =
op(unitOfFile.getOrElse(source.file, new RichCompilationUnit(source)))
- /** The compilation unit corresponding to a source file
- * if it does not yet exist create a new one atomically
- * Note: We want to get roid of this operation as it messes compiler invariants.
- */
- @deprecated("use getUnitOf(s) or onUnitOf(s) instead", "2.10.0")
- def unitOf(s: SourceFile): RichCompilationUnit = getOrCreateUnitOf(s)
-
- /** The compilation unit corresponding to a position */
- @deprecated("use getUnitOf(pos.source) or onUnitOf(pos.source) instead", "2.10.0")
- def unitOf(pos: Position): RichCompilationUnit = getOrCreateUnitOf(pos.source)
-
/** Removes the CompilationUnit corresponding to the given SourceFile
* from consideration for recompilation.
*/
@@ -229,18 +218,6 @@ trait CompilerControl { self: Global =>
def askParsedEntered(source: SourceFile, keepLoaded: Boolean, response: Response[Tree]) =
postWorkItem(new AskParsedEnteredItem(source, keepLoaded, response))
- /** Set sync var `response` to a pair consisting of
- * - the fully qualified name of the first top-level object definition in the file.
- * or "" if there are no object definitions.
- * - the text of the instrumented program which, when run,
- * prints its output and all defined values in a comment column.
- *
- * @param source The source file to be analyzed
- * @param response The response.
- */
- @deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- def askInstrumented(source: SourceFile, line: Int, response: Response[(String, Array[Char])]) =
- postWorkItem(new AskInstrumentedItem(source, line, response))
/** Cancels current compiler run and start a fresh one where everything will be re-typechecked
* (but not re-loaded).
@@ -250,11 +227,6 @@ trait CompilerControl { self: Global =>
/** Tells the compile server to shutdown, and not to restart again */
def askShutdown() = scheduler raise ShutdownReq
- @deprecated("use parseTree(source) instead", "2.10.0") // deleted 2nd parameter, as this has to run on 2.8 also.
- def askParse(source: SourceFile, response: Response[Tree]) = respond(response) {
- parseTree(source)
- }
-
/** Returns parse tree for source `source`. No symbols are entered. Syntax errors are reported.
*
* This method is thread-safe and as such can safely run outside of the presentation
@@ -419,15 +391,6 @@ trait CompilerControl { self: Global =>
response raise new MissingResponse
}
- @deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- case class AskInstrumentedItem(source: SourceFile, line: Int, response: Response[(String, Array[Char])]) extends WorkItem {
- def apply() = self.getInstrumented(source, line, response)
- override def toString = "getInstrumented "+source
-
- def raiseMissing() =
- response raise new MissingResponse
- }
-
/** A do-nothing work scheduler that responds immediately with MissingResponse.
*
* Used during compiler shutdown.
diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala
index da838e0f83..a1878c77e0 100644
--- a/src/interactive/scala/tools/nsc/interactive/Global.scala
+++ b/src/interactive/scala/tools/nsc/interactive/Global.scala
@@ -100,7 +100,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
with CompilerControl
with ContextTrees
with RichCompilationUnits
- with ScratchPadMaker
with Picklers {
import definitions._
@@ -1171,18 +1170,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
}
}
- @deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- def getInstrumented(source: SourceFile, line: Int, response: Response[(String, Array[Char])]) {
- try {
- interruptsEnabled = false
- respond(response) {
- instrument(source, line)
- }
- } finally {
- interruptsEnabled = true
- }
- }
-
// ---------------- Helper classes ---------------------------
/** The typer run */
diff --git a/src/interactive/scala/tools/nsc/interactive/REPL.scala b/src/interactive/scala/tools/nsc/interactive/REPL.scala
index 33981771ec..8e9b0ceee0 100644
--- a/src/interactive/scala/tools/nsc/interactive/REPL.scala
+++ b/src/interactive/scala/tools/nsc/interactive/REPL.scala
@@ -9,7 +9,6 @@ package interactive
import scala.reflect.internal.util._
import scala.tools.nsc.reporters._
import scala.tools.nsc.io._
-import scala.tools.nsc.scratchpad.SourceInserter
import java.io.FileWriter
/** Interface of interactive compiler to a client such as an IDE
@@ -89,8 +88,6 @@ object REPL {
val completeResult = new Response[List[comp.Member]]
val typedResult = new Response[comp.Tree]
val structureResult = new Response[comp.Tree]
- @deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- val instrumentedResult = new Response[(String, Array[Char])]
def makePos(file: String, off1: String, off2: String) = {
val source = toSourceFile(file)
@@ -112,52 +109,6 @@ object REPL {
show(structureResult)
}
- /** Write instrumented source file to disk.
- * @param iFullName The full name of the first top-level object in source
- * @param iContents An Array[Char] containing the instrumented source
- * @return The name of the instrumented source file
- */
- @deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- def writeInstrumented(iFullName: String, suffix: String, iContents: Array[Char]): String = {
- val iSimpleName = iFullName drop ((iFullName lastIndexOf '.') + 1)
- val iSourceName = iSimpleName + suffix
- val ifile = new FileWriter(iSourceName)
- ifile.write(iContents)
- ifile.close()
- iSourceName
- }
-
- /** The method for implementing worksheet functionality.
- * @param arguments a file name, followed by optional command line arguments that are passed
- * to the compiler that processes the instrumented source.
- * @param line A line number that controls uop to which line results should be produced
- * If line = -1, results are produced for all expressions in the worksheet.
- * @return The generated file content containing original source in the left column
- * and outputs in the right column, or None if the presentation compiler
- * does not respond to askInstrumented.
- */
- @deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- def instrument(arguments: List[String], line: Int): Option[(String, String)] = {
- val source = toSourceFile(arguments.head)
- // strip right hand side comment column and any trailing spaces from all lines
- val strippedContents = SourceInserter.stripRight(source.content)
- val strippedSource = new BatchSourceFile(source.file, strippedContents)
- println("stripped source = "+strippedSource+":"+strippedContents.mkString)
- comp.askReload(List(strippedSource), reloadResult)
- comp.askInstrumented(strippedSource, line, instrumentedResult)
- using(instrumentedResult) {
- case (iFullName, iContents) =>
- println(s"instrumented source $iFullName = ${iContents.mkString}")
- val iSourceName = writeInstrumented(iFullName, "$instrumented.scala", iContents)
- val sSourceName = writeInstrumented(iFullName, "$stripped.scala", strippedContents)
- (iSourceName, sSourceName)
-/*
- * val vdirOpt = compileInstrumented(iSourceName, arguments.tail)
- runInstrumented(vdirOpt, iFullName, strippedSource.content)
- */
- }
- }
-
loop { line =>
(line split " ").toList match {
case "reload" :: args =>
@@ -177,10 +128,6 @@ object REPL {
doComplete(makePos(file, off1, off2))
case List("complete", file, off1) =>
doComplete(makePos(file, off1, off1))
- case "instrument" :: arguments =>
- println(instrument(arguments, -1))
- case "instrumentTo" :: line :: arguments =>
- println(instrument(arguments, line.toInt))
case List("quit") =>
comp.askShutdown()
sys.exit(1)
@@ -195,8 +142,6 @@ object REPL {
| typeat <file> <pos>
| complete <file> <start-pos> <end-pos>
| compile <file> <pos>
- | instrument <file> <arg>*
- | instrumentTo <line-num> <file> <arg>*
| structure <file>
| quit
|""".stripMargin)
diff --git a/src/interactive/scala/tools/nsc/interactive/ScratchPadMaker.scala b/src/interactive/scala/tools/nsc/interactive/ScratchPadMaker.scala
deleted file mode 100644
index 2400b97d97..0000000000
--- a/src/interactive/scala/tools/nsc/interactive/ScratchPadMaker.scala
+++ /dev/null
@@ -1,201 +0,0 @@
-package scala
-package tools.nsc
-package interactive
-
-import scala.reflect.internal.util.{SourceFile, BatchSourceFile, RangePosition}
-import scala.collection.mutable.ArrayBuffer
-import scala.reflect.internal.Chars.{isLineBreakChar, isWhitespace}
-import ast.parser.Tokens._
-
-@deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
-trait ScratchPadMaker { self: Global =>
-
- import definitions._
-
- private case class Patch(offset: Int, text: String)
-
- private class Patcher(contents: Array[Char], lex: LexicalStructure, endOffset: Int) extends Traverser {
- var objectName: String = ""
-
- private val patches = new ArrayBuffer[Patch]
- private val toPrint = new ArrayBuffer[String]
- private var skipped = 0
- private var resNum: Int = -1
-
- private def nextRes(): String = {
- resNum += 1
- "res$"+resNum
- }
-
- private def nameType(name: String, tpe: Type): String = {
- // if name ends in symbol character, add a space to separate it from the following ':'
- val pad = if (Character.isLetter(name.last) || Character.isDigit(name.last)) "" else " "
- name+pad+": "+tpe
- }
-
- private def nameType(sym: Symbol): String = nameType(sym.name.decoded, sym.tpe)
-
- private def literal(str: String) = "\"\"\""+str+"\"\"\""
-
- private val prologue = ";import scala.runtime.WorksheetSupport._; def main(args: Array[String])=$execute{"
-
- private val epilogue = "}"
-
- private def applyPendingPatches(offset: Int) = {
- if (skipped == 0) patches += Patch(offset, prologue)
- for (msg <- toPrint) patches += Patch(offset, ";System.out.println("+msg+")")
- toPrint.clear()
- }
-
- /** The position where to insert an instrumentation statement in front of given statement.
- * This is at the latest `stat.pos.start`. But in order not to mess with column numbers
- * in position we try to insert it at the end of the previous token instead.
- * Furthermore, `(' tokens have to be skipped because they do not show up
- * in statement range positions.
- */
- private def instrumentPos(start: Int): Int = {
- val (prevToken, prevStart, prevEnd) = lex.locate(start - 1)
- if (prevStart >= start) start
- else if (prevToken == LPAREN) instrumentPos(prevStart)
- else prevEnd
- }
-
- private def addSkip(stat: Tree): Unit = {
- val ipos = instrumentPos(stat.pos.start)
- if (stat.pos.start > skipped) applyPendingPatches(ipos)
- if (stat.pos.start >= endOffset)
- patches += Patch(ipos, ";$stop()")
- var end = stat.pos.end
- if (end > skipped) {
- while (end < contents.length && !isLineBreakChar(contents(end))) end += 1
- patches += Patch(ipos, ";$skip("+(end-skipped)+"); ")
- skipped = end
- }
- }
-
- private def addSandbox(expr: Tree) = {}
-// patches += (Patch(expr.pos.start, "sandbox("), Patch(expr.pos.end, ")"))
-
- private def resultString(prefix: String, expr: String) =
- literal(prefix + " = ") + " + $show(" + expr + ")"
-
- private def traverseStat(stat: Tree) =
- if (stat.pos.isInstanceOf[RangePosition]) {
- stat match {
- case ValDef(_, _, _, rhs) =>
- addSkip(stat)
- if (stat.symbol.isLazy)
- toPrint += literal(nameType(stat.symbol) + " = <lazy>")
- else if (!stat.symbol.isSynthetic) {
- addSandbox(rhs)
- toPrint += resultString(nameType(stat.symbol), stat.symbol.name.toString)
- }
- case DefDef(_, _, _, _, _, _) =>
- addSkip(stat)
- toPrint += literal(nameType(stat.symbol))
- case Annotated(_, arg) =>
- traverse(arg)
- case DocDef(_, defn) =>
- traverse(defn)
- case _ =>
- if (stat.isTerm) {
- addSkip(stat)
- if (stat.tpe.typeSymbol == UnitClass) {
- addSandbox(stat)
- } else {
- val resName = nextRes()
- val dispResName = resName filter ('$' != _)
- val offset = instrumentPos(stat.pos.start)
- patches += Patch(offset, "val " + resName + " = ")
- addSandbox(stat)
- toPrint += resultString(nameType(dispResName, stat.tpe), resName)
- }
- }
- }
- }
-
- override def traverse(tree: Tree): Unit = tree match {
- case PackageDef(_, _) =>
- 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)
- patches += Patch(skipped, epilogue)
- }
- }
- case _ =>
- }
-
- /** The patched text.
- * @require traverse is run first
- */
- def result: Array[Char] = {
- val reslen = contents.length + (patches map (_.text.length)).sum
- val res = Array.ofDim[Char](reslen)
- var lastOffset = 0
- var from = 0
- var to = 0
- for (Patch(offset, text) <- patches) {
- val delta = offset - lastOffset
- assert(delta >= 0)
- Array.copy(contents, from, res, to, delta)
- from += delta
- to += delta
- lastOffset = offset
- text.copyToArray(res, to)
- to += text.length
- }
- assert(contents.length - from == reslen - to)
- Array.copy(contents, from, res, to, contents.length - from)
- res
- }
- }
-
- class LexicalStructure(source: SourceFile) {
- val token = new ArrayBuffer[Int]
- val startOffset = new ArrayBuffer[Int]
- val endOffset = new ArrayBuffer[Int]
- private val scanner = new syntaxAnalyzer.UnitScanner(new CompilationUnit(source))
- scanner.init()
- while (scanner.token != EOF) {
- startOffset += scanner.offset
- token += scanner.token
- scanner.nextToken()
- endOffset += scanner.lastOffset
- }
-
- /** @return token that starts before or at offset, its startOffset, its endOffset
- */
- def locate(offset: Int): (Int, Int, Int) = {
- var lo = 0
- var hi = token.length - 1
- while (lo < hi) {
- val mid = (lo + hi + 1) / 2
- if (startOffset(mid) <= offset) lo = mid
- else hi = mid - 1
- }
- (token(lo), startOffset(lo), endOffset(lo))
- }
- }
-
- /** Compute an instrumented version of a sourcefile.
- * @param source The given sourcefile.
- * @param line The line up to which results should be printed, -1 = whole document.
- * @return A pair consisting of
- * - the fully qualified name of the first top-level object definition in the file.
- * or "" if there are no object definitions.
- * - the text of the instrumented program which, when run,
- * prints its output and all defined values in a comment column.
- */
- protected def instrument(source: SourceFile, line: Int): (String, Array[Char]) = {
- val tree = typedTree(source, forceReload = true)
- val endOffset = if (line < 0) source.length else source.lineToOffset(line + 1)
- val patcher = new Patcher(source.content, new LexicalStructure(source), endOffset)
- patcher.traverse(tree)
- (patcher.objectName, patcher.result)
- }
-}