diff options
author | Miles Sabin <miles@milessabin.com> | 2009-07-31 21:31:02 +0000 |
---|---|---|
committer | Miles Sabin <miles@milessabin.com> | 2009-07-31 21:31:02 +0000 |
commit | 11ee847d384dcd0f45295380809f66961ebe25a3 (patch) | |
tree | 2a074650c871a72577cb8c05d9228e967544110f | |
parent | 1a4566278cdaed86891f7c675c3d52a52379f029 (diff) | |
download | scala-11ee847d384dcd0f45295380809f66961ebe25a3.tar.gz scala-11ee847d384dcd0f45295380809f66961ebe25a3.tar.bz2 scala-11ee847d384dcd0f45295380809f66961ebe25a3.zip |
Added notification to BuildManager clients of f...
Added notification to BuildManager clients of files as they're compiled
allowing IDEs to clear persistent compilation related state; added a
mechanism to request a type tree corresponding to an entire compilation
unit.
6 files changed, 39 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala index f46ab29e37..e78ab615f7 100644 --- a/src/compiler/scala/tools/nsc/Main.scala +++ b/src/compiler/scala/tools/nsc/Main.scala @@ -49,6 +49,7 @@ object Main extends AnyRef with EvalLoop { if (command.settings.version.value) reporter.info(null, versionMsg, true) else if (command.settings.Yidedebug.value) { + command.settings.Xprintpos.value = true val compiler = new interactive.Global(command.settings, reporter) import compiler.{ reporter => _, _ } diff --git a/src/compiler/scala/tools/nsc/interactive/BuildManager.scala b/src/compiler/scala/tools/nsc/interactive/BuildManager.scala index 1bb3217095..0b35920ca2 100644 --- a/src/compiler/scala/tools/nsc/interactive/BuildManager.scala +++ b/src/compiler/scala/tools/nsc/interactive/BuildManager.scala @@ -22,6 +22,9 @@ trait BuildManager { */ def update(added: Set[AbstractFile], removed: Set[AbstractFile]) + /** Notification that the supplied set of files is being built */ + def buildingFiles(included: Set[AbstractFile]) {} + /** Load saved dependency information. */ def loadFrom(file: AbstractFile) diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala index 942a6f5c86..b22cc9098d 100644 --- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala +++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala @@ -82,6 +82,11 @@ trait CompilerControl { self: Global => override def toString = "typeat "+pos.source+" "+pos.show } + def askType(source: SourceFile, forceReload: Boolean, result: Response[Tree]) = + scheduler postWorkItem new WorkItem { + def apply() = self.getTypedTree(source, forceReload, result) + } + /** Set sync var `result' to list of members that are visible * as members of the tree enclosing `pos`, possibly reachable by an implicit. * - if `selection` is false, as identifiers in the scope enclosing `pos` diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 4b87a9e030..4ca2203bb2 100755 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -24,8 +24,6 @@ self => import definitions._ - settings.Xprintpos.value = true - override def onlyPresentation = true /** A list indicating in which order some units should be typechecked. @@ -122,14 +120,14 @@ self => case Some(action) => try { acting = true - println("picked up work item: "+action) + //println("picked up work item: "+action) action() - println("done with work item: "+action) + //println("done with work item: "+action) } catch { case ex: CancelActionReq => - println("cancelled work item: "+action) + //println("cancelled work item: "+action) } finally { - println("quitting work item: "+action) + //println("quitting work item: "+action) acting = false } case None => @@ -211,13 +209,13 @@ self => /** Compile all given units */ private def backgroundCompile() { - inform("Starting new presentation compiler type checking pass") + //inform("Starting new presentation compiler type checking pass") reporter.reset firsts = firsts filter (s => unitOfFile contains (s.file)) val prefix = firsts map unitOf val units = prefix ::: (unitOfFile.values.toList diff prefix) filter (!_.isUpToDate) recompile(units) - inform("Everything is now up to date") + //inform("Everything is now up to date") } /** Reset unit to just-parsed state */ @@ -300,11 +298,25 @@ self => new Locator(pos) locateIn typedTree } + /** A fully attributed tree corresponding to the entire compilation unit */ + def typedTree(source: SourceFile, forceReload: Boolean): Tree = { + val unit = unitOf(source) + val sources = List(source) + if (unit.status == NotLoaded || forceReload) reloadSources(sources) + moveToFront(sources) + currentTyperRun.typedTree(unitOf(source)) + } + /** Set sync var `result` to a fully attributed tree located at position `pos` */ def getTypedTreeAt(pos: Position, result: Response[Tree]) { respond(result)(typedTreeAt(pos)) } + /** Set sync var `result` to a fully attributed tree corresponding to the entire compilation unit */ + def getTypedTree(source : SourceFile, forceReload: Boolean, result: Response[Tree]) { + respond(result)(typedTree(source, forceReload)) + } + def stabilizedType(tree: Tree): Type = tree match { case Ident(_) if tree.symbol.isStable => singleType(NoPrefix, tree.symbol) case Select(qual, _) if tree.symbol.isStable => singleType(qual.tpe, tree.symbol) @@ -403,8 +415,6 @@ self => /** The typer run */ class TyperRun extends Run { - println("new typer run") - // units is always empty // symSource, symData are ignored override def compiles(sym: Symbol) = false @@ -440,6 +450,13 @@ self => } } + def typedTree(unit: RichCompilationUnit): Tree = { + assert(unit.status >= JustParsed) + unit.targetPos = NoPosition + typeCheck(unit) + unit.body + } + /** Apply a phase to a compilation unit * @return true iff typechecked correctly */ diff --git a/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala b/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala index 325fe586db..c0849065f6 100644 --- a/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala +++ b/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala @@ -74,9 +74,9 @@ class RefinedBuildManager(val settings: Settings) extends Changes with BuildMana * have been previously added as source files are recompiled. */ private def update(files: Set[AbstractFile]): Unit = if (!files.isEmpty) { - val deps = compiler.dependencyAnalysis.dependencies val run = compiler.newRun() compiler.inform("compiling " + files) + buildingFiles(files) run.compileFiles(files.toList) if (compiler.reporter.hasErrors) { diff --git a/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala b/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala index b3ed0e0abf..37ed782868 100644 --- a/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala +++ b/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala @@ -62,6 +62,8 @@ class SimpleBuildManager(val settings: Settings) extends BuildManager { (if(settings.debug.value) toCompile.mkString(", ") else toCompile.size + " files")) + buildingFiles(toCompile) + run.compileFiles(files.toList) } |