Skip to content

Commit 98b61dd

Browse files
committed
Fix #25: move doc related structures to DocBase
To access `DocBase`: `ctx.docbase.docstring(...)`
1 parent 553f9b2 commit 98b61dd

File tree

9 files changed

+27
-17
lines changed

9 files changed

+27
-17
lines changed

dottydoc/jvm/src/dotty/tools/dottydoc/core/DocASTPhase.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DocASTPhase extends Phase {
3737

3838
/** Build documentation hierarchy from existing tree */
3939
def collect(tree: Tree, prev: List[String] = Nil)(implicit ctx: Context): Entity = track(tree.symbol, ctx) {
40-
val implicitlyAddedMembers = ctx.base.defs(tree.symbol)
40+
val implicitlyAddedMembers = ctx.docbase.defs(tree.symbol)
4141

4242
def collectList(xs: List[Tree], ps: List[String])(implicit ctx: Context): List[Entity] =
4343
xs.map(collect(_, ps)).filter(_ != NonEntity)
@@ -169,7 +169,7 @@ class DocASTPhase extends Phase {
169169
commentParser.clear()
170170

171171
// (5) Update Doc AST in ctx.base
172-
for (kv <- packages) ctx.base.packages += kv
172+
for (kv <- packages) ctx.docbase.packages += kv
173173

174174
// Return super's result
175175
compUnits

dottydoc/jvm/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DocImplicitsPhase extends MiniPhaseTransform { thisTransformer =>
1919
tree.vparamss(0).length == 1 // should only take one arg, since it has to be a transformation
2020
) {
2121
val convertee = tree.vparamss(0)(0).symbol.info.widenDealias.finalResultType.typeSymbol // the pimped type (i.e. `class`)
22-
ctx.base.addDef(convertee, tree.symbol.info.widenDealias.finalResultType.typeSymbol)
22+
ctx.docbase.addDef(convertee, tree.symbol.info.widenDealias.finalResultType.typeSymbol)
2323
}
2424

2525
tree

dottydoc/jvm/src/dotty/tools/dottydoc/core/MiniPhaseTransform.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ object transform {
4343
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
4444
for {
4545
rootName <- rootPackages
46-
pack = ctx.base.packages[Package](rootName)
46+
pack = ctx.docbase.packages[Package](rootName)
4747
transformed = performPackageTransform(pack)
48-
} yield ctx.base.packages(rootName) = transformed
48+
} yield ctx.docbase.packages(rootName) = transformed
4949
super.runOn(units)
5050
}
5151

5252
private def rootPackages(implicit ctx: Context): List[String] = {
5353
var currentDepth = Int.MaxValue
5454
var packs = List.empty[String]
5555

56-
for (key <- ctx.base.packages.keys) {
56+
for (key <- ctx.docbase.packages.keys) {
5757
val keyDepth = key.split("\\.").length
5858
packs =
5959
if (keyDepth < currentDepth) {

dottydoc/jvm/src/dotty/tools/dottydoc/core/PrintPhase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PrintPhase extends Phase {
1616

1717
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
1818
val compUnits = super.runOn(units)
19-
val packages = ctx.base.packages[Package].toMap
19+
val packages = ctx.docbase.packages[Package].toMap
2020

2121
val outputDir = {
2222
val out = ctx.settings.DocOutput.value

dottydoc/jvm/src/dotty/tools/dottydoc/core/TypeLinkingPhases.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import util.internal.setters._
1616

1717
class LinkReturnTypes extends DocMiniPhase with TypeLinker {
1818
override def transformDef(implicit ctx: Context) = { case df: DefImpl =>
19-
val returnValue = linkReference(df, df.returnValue, ctx.base.packages[Package].toMap)
19+
val returnValue = linkReference(df, df.returnValue, ctx.docbase.packages[Package].toMap)
2020
df.copy(returnValue = returnValue)
2121
}
2222

2323
override def transformVal(implicit ctx: Context) = { case vl: ValImpl =>
24-
val returnValue = linkReference(vl, vl.returnValue, ctx.base.packages[Package].toMap)
24+
val returnValue = linkReference(vl, vl.returnValue, ctx.docbase.packages[Package].toMap)
2525
vl.copy(returnValue = returnValue)
2626
}
2727
}
@@ -30,7 +30,7 @@ class LinkParamListTypes extends DocMiniPhase with TypeLinker {
3030
override def transformDef(implicit ctx: Context) = { case df: DefImpl =>
3131
val newParamLists = for {
3232
ParamListImpl(list, isImplicit) <- df.paramLists
33-
newList = list.map(linkReference(df, _, ctx.base.packages[Package].toMap))
33+
newList = list.map(linkReference(df, _, ctx.docbase.packages[Package].toMap))
3434
} yield ParamListImpl(newList.asInstanceOf[List[NamedReference]], isImplicit)
3535

3636
df.copy(paramLists = newParamLists)

dottydoc/jvm/src/dotty/tools/dottydoc/model/comment/CommentExpander.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ trait CommentExpander {
7777

7878
def cookedDocComment(sym: Symbol, docStr: String = "")(implicit ctx: Context): String = cookedDocComments.getOrElseUpdate(sym, {
7979
var ownComment =
80-
if (docStr.length == 0) ctx.base.docstring(sym).map(c => template(c.chrs)).getOrElse("")
80+
if (docStr.length == 0) ctx.docbase.docstring(sym).map(c => template(c.chrs)).getOrElse("")
8181
else template(docStr)
8282
ownComment = replaceInheritDocToInheritdoc(ownComment)
8383

@@ -287,7 +287,7 @@ trait CommentExpander {
287287
def defineVariables(sym: Symbol)(implicit ctx: Context) = {
288288
val Trim = "(?s)^[\\s&&[^\n\r]]*(.*?)\\s*$".r
289289

290-
val raw = ctx.base.docstring(sym).map(_.chrs).getOrElse("")
290+
val raw = ctx.docbase.docstring(sym).map(_.chrs).getOrElse("")
291291
defs(sym) ++= defines(raw).map {
292292
str => {
293293
val start = skipWhitespace(str, "@define".length)
@@ -328,7 +328,7 @@ trait CommentExpander {
328328
* the position of the doc comment of the overridden version is returned instead.
329329
*/
330330
def docCommentPos(sym: Symbol)(implicit ctx: Context): Position =
331-
ctx.base.docstring(sym).map(_.pos).getOrElse(NoPosition)
331+
ctx.docbase.docstring(sym).map(_.pos).getOrElse(NoPosition)
332332

333333
/** A version which doesn't consider self types, as a temporary measure:
334334
* an infinite loop has broken out between superComment and cookedDocComment

dottydoc/jvm/src/dotty/tools/dottydoc/model/parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object parsers {
2323
* which can then be awaited near the end of the run - before the pickling.
2424
*/
2525
def parseHtml(sym: Symbol, entity: Entity, packages: Map[String, Package])(implicit ctx: Context): (String, Option[Comment]) = {
26-
val cmt = ctx.base.docstring(sym).map { d =>
26+
val cmt = ctx.docbase.docstring(sym).map { d =>
2727
val expanded = expand(sym)
2828
val body = parse(entity, packages, clean(expanded), expanded, d.pos)
2929
val summary = body.summary.map(_.toHtml(entity)).getOrElse("")
@@ -43,7 +43,7 @@ object parsers {
4343
}
4444

4545
val path = entity.path.mkString(".")
46-
if (!commentCache.contains(path) || ctx.base.docstring(symbol).isDefined)
46+
if (!commentCache.contains(path) || ctx.docbase.docstring(symbol).isDefined)
4747
commentCache = commentCache + (path -> commentParser)
4848
}
4949

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ object Contexts {
532532
/** The symbol loaders */
533533
val loaders = new SymbolLoaders
534534

535+
/** Documentation base */
536+
val docbase = new DocBase
537+
535538
/** The platform, initialized by `initPlatform()`. */
536539
private var _platform: Platform = _
537540

@@ -568,15 +571,22 @@ object Contexts {
568571
def squashed(p: Phase): Phase = {
569572
allPhases.find(_.period.containsPhaseId(p.id)).getOrElse(NoPhase)
570573
}
574+
}
571575

572-
val _docstrings: mutable.Map[Symbol, Comment] =
576+
class DocBase {
577+
private[this] val _docstrings: mutable.Map[Symbol, Comment] =
573578
mutable.Map.empty
574579

575580
def docstring(sym: Symbol): Option[Comment] = _docstrings.get(sym)
576581

577582
def addDocstring(sym: Symbol, doc: Option[Comment]): Unit =
578583
doc.map(d => _docstrings += (sym -> d))
579584

585+
/*
586+
* Dottydoc places instances of `Package` in this map - but we do not want
587+
* to depend on `dottydoc` for the compiler, as such this is defined as a
588+
* map of `String -> AnyRef`
589+
*/
580590
private[this] val _packages: mutable.Map[String, AnyRef] = mutable.Map.empty
581591
def packages[A]: mutable.Map[String, A] = _packages.asInstanceOf[mutable.Map[String, A]]
582592

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class Namer { typer: Typer =>
426426
}
427427

428428
def setDocstring(sym: Symbol, tree: Tree)(implicit ctx: Context) = tree match {
429-
case t: MemberDef => ctx.base.addDocstring(sym, t.rawComment)
429+
case t: MemberDef => ctx.docbase.addDocstring(sym, t.rawComment)
430430
case _ => ()
431431
}
432432

0 commit comments

Comments
 (0)