aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-03-10 19:26:05 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-04-07 08:40:28 +0200
commit844683edb78f45bf37949bd923f56fc98a68c837 (patch)
tree426ab969895f2053c3f65c6976613257e0d0aeb2 /src/dotty/tools
parent8513dd692cf690a48b69329b60e1cbb852842f12 (diff)
downloaddotty-844683edb78f45bf37949bd923f56fc98a68c837.tar.gz
dotty-844683edb78f45bf37949bd923f56fc98a68c837.tar.bz2
dotty-844683edb78f45bf37949bd923f56fc98a68c837.zip
Implement comments as attachments instead of tree members
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/ast/Trees.scala11
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala18
-rw-r--r--src/dotty/tools/dotc/parsing/Scanners.scala4
3 files changed, 15 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala
index eb5ab15e3..be3e2eb5f 100644
--- a/src/dotty/tools/dotc/ast/Trees.scala
+++ b/src/dotty/tools/dotc/ast/Trees.scala
@@ -29,6 +29,9 @@ object Trees {
/** The total number of created tree nodes, maintained if Stats.enabled */
@sharable var ntrees = 0
+ /** Attachment key for trees with documentation strings attached */
+ val DocComment = new Attachment.Key[String]
+
/** Modifiers and annotations for definitions
* @param flags The set flags
* @param privateWithin If a private or protected has is followed by a
@@ -321,9 +324,7 @@ object Trees {
private[ast] def rawMods: Modifiers[T] =
if (myMods == null) genericEmptyModifiers else myMods
- private[this] var myComment: Option[String] = None
-
- def rawComment: Option[String] = myComment
+ def rawComment: Option[String] = getAttachment(DocComment)
def withMods(mods: Modifiers[Untyped]): ThisTree[Untyped] = {
val tree = if (myMods == null || (myMods == mods)) this else clone.asInstanceOf[MemberDef[Untyped]]
@@ -333,8 +334,8 @@ object Trees {
def withFlags(flags: FlagSet): ThisTree[Untyped] = withMods(Modifiers(flags))
- def withComment(cmt: Option[String]): ThisTree[Untyped] = {
- myComment = cmt
+ def setComment(comment: Option[String]): ThisTree[Untyped] = {
+ comment.map(putAttachment(DocComment, _))
asInstanceOf[ThisTree[Untyped]]
}
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index dad618381..cdfc366a7 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -1782,9 +1782,9 @@ object Parsers {
}
} else EmptyTree
lhs match {
- case (id @ Ident(name: TermName)) :: Nil =>
- cpy.ValDef(id)(name, tpt, rhs).withMods(mods).withComment(docstring)
- case _ =>
+ case (id @ Ident(name: TermName)) :: Nil => {
+ cpy.ValDef(id)(name, tpt, rhs).withMods(mods).setComment(docstring)
+ } case _ =>
PatDef(mods, lhs, tpt, rhs)
}
}
@@ -1835,7 +1835,7 @@ object Parsers {
accept(EQUALS)
expr()
}
- DefDef(name, tparams, vparamss, tpt, rhs).withMods(mods1).withComment(docstring)
+ DefDef(name, tparams, vparamss, tpt, rhs).withMods(mods1).setComment(docstring)
}
}
@@ -1877,7 +1877,7 @@ object Parsers {
in.token match {
case EQUALS =>
in.nextToken()
- TypeDef(name, tparams, typ()).withMods(mods).withComment(docstring)
+ TypeDef(name, tparams, typ()).withMods(mods).setComment(docstring)
case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | EOF =>
TypeDef(name, tparams, typeBounds()).withMods(mods)
case _ =>
@@ -1923,9 +1923,7 @@ object Parsers {
}
val templ = templateOpt(constr)
- TypeDef(name, templ)
- .withMods(mods)
- .withComment(docstring)
+ TypeDef(name, templ).withMods(mods).setComment(docstring)
}
/** ConstrMods ::= AccessModifier
@@ -1945,9 +1943,7 @@ object Parsers {
val name = ident()
val template = templateOpt(emptyConstructor())
- ModuleDef(name, template)
- .withMods(mods)
- .withComment(docstring)
+ ModuleDef(name, template).withMods(mods).setComment(docstring)
}
/* -------- TEMPLATES ------------------------------------------- */
diff --git a/src/dotty/tools/dotc/parsing/Scanners.scala b/src/dotty/tools/dotc/parsing/Scanners.scala
index 5ec6823e4..4211b6275 100644
--- a/src/dotty/tools/dotc/parsing/Scanners.scala
+++ b/src/dotty/tools/dotc/parsing/Scanners.scala
@@ -180,12 +180,12 @@ object Scanners {
/** All comments in the reverse order of their position in the source.
* set only when `keepComments` is true.
*/
- var revComments: List[Comment] = Nil
+ private[this] var revComments: List[Comment] = Nil
/** All doc comments as encountered, each list contains doc comments from
* the same block level. Starting with the deepest level and going upward
*/
- var docsPerBlockStack: List[List[Comment]] = List(List())
+ private[this] var docsPerBlockStack: List[List[Comment]] = List(List())
/** Adds level of nesting to docstrings */
def enterBlock(): Unit =