aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
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/tools/dotc/core
parentaf27562040631d0bea38ec3ff8912fda9939f34e (diff)
downloaddotty-208232aba52903ae090711589e9c572dc5347651.tar.gz
dotty-208232aba52903ae090711589e9c572dc5347651.tar.bz2
dotty-208232aba52903ae090711589e9c572dc5347651.zip
Implement docbase as property
Diffstat (limited to 'src/dotty/tools/dotc/core')
-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
3 files changed, 9 insertions, 8 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) ||