Skip to content

Support -from-tasty in Dottydoc #4789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support for -from-tasty in Dottydoc
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
commit 28023b440de7481a10548d4153fc4e843129b274
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A front end should probably not be in another frontend. DocCompiler should choose between DocFrontEnd or ReadTastyTreesFromClasses based on ctx.settings.fromTasty.value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wanted to decouple everything, but I ran into issues when cooking the comments. I'll investigate a bit more.

fromTastyFrontend.runOn(units)
} else {
super.runOn(units)
}
}

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