aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-04-07 08:27:43 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-04-07 08:57:05 +0200
commitf43f520a1a6e60d4a6020af97c52dd6c43ea75cd (patch)
tree2d746b4de308c1fc580e00704254b0b843ede5c4 /src/dotty
parent844683edb78f45bf37949bd923f56fc98a68c837 (diff)
downloaddotty-f43f520a1a6e60d4a6020af97c52dd6c43ea75cd.tar.gz
dotty-f43f520a1a6e60d4a6020af97c52dd6c43ea75cd.tar.bz2
dotty-f43f520a1a6e60d4a6020af97c52dd6c43ea75cd.zip
Add binding between Symbol and Untyped tree in base context
This commit also adds a printer for use by dottydoc.
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/config/Printers.scala1
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala16
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala2
4 files changed, 23 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala
index 21147fe6f..fa36ad12c 100644
--- a/src/dotty/tools/dotc/config/Printers.scala
+++ b/src/dotty/tools/dotc/config/Printers.scala
@@ -13,6 +13,7 @@ object Printers {
}
val default: Printer = new Printer
+ val dottydoc: Printer = noPrinter
val core: Printer = noPrinter
val typr: Printer = noPrinter
val constr: Printer = noPrinter
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index a0bb03e50..ad3a0057d 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -550,6 +550,14 @@ object Contexts {
def squashed(p: Phase): Phase = {
allPhases.find(_.period.containsPhaseId(p.id)).getOrElse(NoPhase)
}
+
+ val _docstrings: mutable.Map[Symbol, String] =
+ mutable.Map.empty
+
+ def docstring(sym: Symbol): Option[String] = _docstrings.get(sym)
+
+ def addDocstring(sym: Symbol, doc: Option[String]): Unit =
+ doc.map(d => _docstrings += (sym -> d))
}
/** The essential mutable state of a context base, collected into a common class */
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index de27333d5..82b3b56e9 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -401,19 +401,29 @@ class Namer { typer: Typer =>
val pkg = createPackageSymbol(pcl.pid)
index(pcl.stats)(ctx.fresh.setOwner(pkg.moduleClass))
invalidateCompanions(pkg, Trees.flatten(pcl.stats map expanded))
+ setDocstring(pkg, stat)
ctx
case imp: Import =>
importContext(createSymbol(imp), imp.selectors)
case mdef: DefTree =>
- enterSymbol(createSymbol(mdef))
+ val sym = enterSymbol(createSymbol(mdef))
+ setDocstring(sym, stat)
ctx
case stats: Thicket =>
- for (tree <- stats.toList) enterSymbol(createSymbol(tree))
+ for (tree <- stats.toList) {
+ val sym = enterSymbol(createSymbol(tree))
+ setDocstring(sym, stat)
+ }
ctx
case _ =>
ctx
}
+ def setDocstring(sym: Symbol, tree: Tree)(implicit ctx: Context) = tree match {
+ case t: MemberDef => ctx.base.addDocstring(sym, t.rawComment)
+ case _ => ()
+ }
+
/** Create top-level symbols for statements and enter them into symbol table */
def index(stats: List[Tree])(implicit ctx: Context): Context = {
@@ -859,7 +869,7 @@ class Namer { typer: Typer =>
WildcardType
}
paramFn(typedAheadType(mdef.tpt, tptProto).tpe)
- }
+ }
/** The type signature of a DefDef with given symbol */
def defDefSig(ddef: DefDef, sym: Symbol)(implicit ctx: Context) = {
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 3b8ada2a8..84abf85e0 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -586,7 +586,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case _ => false
}
- /** The funcion body to be returned in the closure. Can become a TypedSplice
+ /** The function body to be returned in the closure. Can become a TypedSplice
* of a typed expression if this is necessary to infer a parameter type.
*/
var fnBody = tree.body