Skip to content

Commit

Permalink
Support for -from-tasty in Dottydoc
Browse files Browse the repository at this point in the history
Dottydoc can now be used in one of two ways:

 - By receiving a list of source files that will be parsed, typed, and
   for which the documentation will be generated
 - When `-from-tasty` is set, by receiving a list of fully qualified
   class names. The trees will be unpickled and the documentation will
   be generated.
  • Loading branch information
Duhemm committed Sep 4, 2018
1 parent 86c4e72 commit 28023b4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
}

def alreadyLoaded(): None.type = {
ctx.warning(s"sclass $className cannot be unpickled because it is already loaded")
ctx.warning(s"class $className cannot be unpickled because it is already loaded")
None
}

Expand Down
15 changes: 14 additions & 1 deletion doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package dottydoc

import core._
import core.transform._
import dotc.core.Contexts.Context
import dotc.core.Phases.Phase
import dotc.Compiler
import dotc.core.Mode
import dotc.{Compiler, Run}

import dotty.tools.dotc.fromtasty.{ReadTastyTreesFromClasses, TASTYRun}

/** Custom Compiler with phases for the documentation tool
*
Expand All @@ -20,6 +24,15 @@ import dotc.Compiler
*/
class DocCompiler extends Compiler {

override def newRun(implicit ctx: Context): Run = {
if (ctx.settings.fromTasty.value) {
reset()
new TASTYRun(this, ctx.addMode(Mode.ReadPositions).addMode(Mode.ReadComments))
} else {
super.newRun
}
}

override protected def frontendPhases: List[List[Phase]] =
List(new DocFrontEnd) :: Nil

Expand Down
11 changes: 11 additions & 0 deletions doc-tool/src/dotty/tools/dottydoc/DocFrontEnd.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools
package dottydoc

import dotc.fromtasty.ReadTastyTreesFromClasses
import dotc.typer.FrontEnd
import dotc.core.Contexts.Context
import dotc.CompilationUnit
Expand All @@ -12,6 +13,16 @@ import dotc.CompilationUnit
* `discardAfterTyper`.
*/
class DocFrontEnd extends FrontEnd {

override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
if (ctx.settings.fromTasty.value) {
val fromTastyFrontend = new ReadTastyTreesFromClasses
fromTastyFrontend.runOn(units)
} else {
super.runOn(units)
}
}

override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) =
unit.isJava
}

0 comments on commit 28023b4

Please sign in to comment.