aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-09-08 20:25:51 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-10-06 17:45:39 +0200
commit208232aba52903ae090711589e9c572dc5347651 (patch)
tree886a60bfa36e690ee81c947bc7d50331affc1bf8 /src/dotty
parentaf27562040631d0bea38ec3ff8912fda9939f34e (diff)
downloaddotty-208232aba52903ae090711589e9c572dc5347651.tar.gz
dotty-208232aba52903ae090711589e9c572dc5347651.tar.bz2
dotty-208232aba52903ae090711589e9c572dc5347651.zip
Implement docbase as property
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/core/Comments.scala6
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala9
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala52
5 files changed, 39 insertions, 33 deletions
diff --git a/src/dotty/tools/dotc/core/Comments.scala b/src/dotty/tools/dotc/core/Comments.scala
index 3e562baff..4f36b3b6b 100644
--- a/src/dotty/tools/dotc/core/Comments.scala
+++ b/src/dotty/tools/dotc/core/Comments.scala
@@ -155,7 +155,7 @@ object Comments {
*/
def cookedDocComment(sym: Symbol, docStr: String = "")(implicit ctx: Context): String = cookedDocComments.getOrElseUpdate(sym, {
var ownComment =
- if (docStr.length == 0) ctx.docbase.docstring(sym).map(c => template(c.raw)).getOrElse("")
+ if (docStr.length == 0) ctx.getDocbase.flatMap(_.docstring(sym).map(c => template(c.raw))).getOrElse("")
else template(docStr)
ownComment = replaceInheritDocToInheritdoc(ownComment)
@@ -365,7 +365,7 @@ object Comments {
def defineVariables(sym: Symbol)(implicit ctx: Context) = {
val Trim = "(?s)^[\\s&&[^\n\r]]*(.*?)\\s*$".r
- val raw = ctx.docbase.docstring(sym).map(_.raw).getOrElse("")
+ val raw = ctx.getDocbase.flatMap(_.docstring(sym).map(_.raw)).getOrElse("")
defs(sym) ++= defines(raw).map {
str => {
val start = skipWhitespace(str, "@define".length)
@@ -406,7 +406,7 @@ object Comments {
* the position of the doc comment of the overridden version is returned instead.
*/
def docCommentPos(sym: Symbol)(implicit ctx: Context): Position =
- ctx.docbase.docstring(sym).map(_.pos).getOrElse(NoPosition)
+ ctx.getDocbase.flatMap(_.docstring(sym).map(_.pos)).getOrElse(NoPosition)
/** A version which doesn't consider self types, as a temporary measure:
* an infinite loop has broken out between superComment and cookedDocComment
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index 3378f0790..bf171bf60 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -69,6 +69,9 @@ object Contexts {
/** The context base at the root */
val base: ContextBase
+ /** Documentation base */
+ def getDocbase = property(DocContext)
+
/** All outer contexts, ending in `base.initialCtx` and then `NoContext` */
def outersIterator = new Iterator[Context] {
var current = thiscontext
@@ -537,9 +540,6 @@ object Contexts {
/** The symbol loaders */
val loaders = new SymbolLoaders
- /** Documentation base */
- val docbase = new DocBase
-
/** The platform, initialized by `initPlatform()`. */
private var _platform: Platform = _
@@ -578,6 +578,7 @@ object Contexts {
}
}
+ val DocContext = new Key[DocBase]
class DocBase {
private[this] val _docstrings: mutable.Map[Symbol, Comment] =
mutable.Map.empty
@@ -597,7 +598,7 @@ object Contexts {
* map of `String -> AnyRef`
*/
private[this] val _packages: mutable.Map[String, AnyRef] = mutable.Map.empty
- def packages[A]: mutable.Map[String, A] = _packages.asInstanceOf[mutable.Map[String, A]]
+ def packagesAs[A]: mutable.Map[String, A] = _packages.asInstanceOf[mutable.Map[String, A]]
/** Should perhaps factorize this into caches that get flushed */
private var _defs: Map[Symbol, Set[Symbol]] = Map.empty
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 018b050ff..e2cb378b5 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -1541,7 +1541,7 @@ object SymDenotations {
/** Enter a symbol in given `scope` without potentially replacing the old copy. */
def enterNoReplace(sym: Symbol, scope: MutableScope)(implicit ctx: Context): Unit = {
- def isUsecase = sym.name.show.takeRight(4) == "$doc"
+ def isUsecase = ctx.property(DocContext).isDefined && sym.name.show.takeRight(4) == "$doc"
require(
(sym.denot.flagsUNSAFE is Private) ||
!(this is Frozen) ||
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 1d2d59208..938b280d1 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -456,7 +456,8 @@ class Namer { typer: Typer =>
def setDocstring(sym: Symbol, tree: Tree)(implicit ctx: Context) = tree match {
- case t: MemberDef if t.rawComment.isDefined => ctx.docbase.addDocstring(sym, t.rawComment)
+ case t: MemberDef if t.rawComment.isDefined =>
+ ctx.getDocbase.foreach(_.addDocstring(sym, t.rawComment))
case _ => ()
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 3291cb9d0..3ed6c9228 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1247,7 +1247,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val dummy = localDummy(cls, impl)
val body1 = typedStats(impl.body, dummy)(inClassContext(self1.symbol))
- typedUsecases(body1.map(_.symbol), self1.symbol)(localContext(cdef, cls).setNewScope)
+ if (ctx.property(DocContext).isDefined)
+ typedUsecases(body1.map(_.symbol), self1.symbol)(localContext(cdef, cls).setNewScope)
checkNoDoubleDefs(cls)
val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1)
@@ -1537,39 +1538,42 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
tpd.cpy.DefDef(mdef)(rhs = Inliner.bodyToInline(mdef.symbol)) ::
Inliner.removeInlineAccessors(mdef.symbol)
- private def typedUsecases(syms: List[Symbol], owner: Symbol)(implicit ctx: Context): Unit = {
- val relevantSyms = syms.filter(ctx.docbase.docstring(_).isDefined)
- relevantSyms.foreach { sym =>
- expandParentDocs(sym)
- val usecases = ctx.docbase.docstring(sym).map(_.usecases).getOrElse(Nil)
+ private def typedUsecases(syms: List[Symbol], owner: Symbol)(implicit ctx: Context): Unit =
+ ctx.getDocbase.foreach { docbase =>
+ val relevantSyms = syms.filter(docbase.docstring(_).isDefined)
+ relevantSyms.foreach { sym =>
+ expandParentDocs(sym)
+ val usecases = docbase.docstring(sym).map(_.usecases).getOrElse(Nil)
- usecases.foreach { usecase =>
- enterSymbol(createSymbol(usecase.untpdCode))
+ usecases.foreach { usecase =>
+ enterSymbol(createSymbol(usecase.untpdCode))
- typedStats(usecase.untpdCode :: Nil, owner) match {
- case List(df: tpd.DefDef) => usecase.tpdCode = df
- case _ => ctx.error("`@usecase` was not a valid definition", usecase.codePos)
+ typedStats(usecase.untpdCode :: Nil, owner) match {
+ case List(df: tpd.DefDef) => usecase.tpdCode = df
+ case _ => ctx.error("`@usecase` was not a valid definition", usecase.codePos)
+ }
}
}
}
- }
private def expandParentDocs(sym: Symbol)(implicit ctx: Context): Unit =
- ctx.docbase.docstring(sym).foreach { cmt =>
- def expandDoc(owner: Symbol): Unit = if (!cmt.isExpanded) {
- val tplExp = ctx.docbase.templateExpander
- tplExp.defineVariables(sym)
+ ctx.getDocbase.foreach { docbase =>
+ docbase.docstring(sym).foreach { cmt =>
+ def expandDoc(owner: Symbol): Unit = if (!cmt.isExpanded) {
+ val tplExp = docbase.templateExpander
+ tplExp.defineVariables(sym)
- val newCmt = cmt
- .expand(tplExp.expandedDocComment(sym, owner, _))
- .withUsecases
+ val newCmt = cmt
+ .expand(tplExp.expandedDocComment(sym, owner, _))
+ .withUsecases
- ctx.docbase.addDocstring(sym, Some(newCmt))
- }
+ docbase.addDocstring(sym, Some(newCmt))
+ }
- if (sym ne NoSymbol) {
- expandParentDocs(sym.owner)
- expandDoc(sym.owner)
+ if (sym ne NoSymbol) {
+ expandParentDocs(sym.owner)
+ expandDoc(sym.owner)
+ }
}
}