diff options
author | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-02-18 15:23:07 +0400 |
---|---|---|
committer | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-02-19 14:36:55 +0400 |
commit | 4df9e20349f08ae59aa75e93d5874b87285c9d6a (patch) | |
tree | 830676cac110d5a7c8941835571c8329c739bed2 | |
parent | 466fc670a38836dfb81d75f72d46ddcaa12bc3bb (diff) | |
download | scala-4df9e20349f08ae59aa75e93d5874b87285c9d6a.tar.gz scala-4df9e20349f08ae59aa75e93d5874b87285c9d6a.tar.bz2 scala-4df9e20349f08ae59aa75e93d5874b87285c9d6a.zip |
SI-7143 Fix scanner docComment: docBuffer and docPos are initialized
in different places and as a result can get out of sync and as a result
the invariant that docComment has a position is broken.
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 79f0bcf149..c05906c740 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -142,24 +142,16 @@ trait Scanners extends ScannersCommon { /** Should doc comments be built? */ def buildDocs: Boolean = forScaladoc - /** buffer for the documentation comment + /** holder for the documentation comment */ - var docBuffer: StringBuilder = null - var docPos: Position = null + var docComment: DocComment = null - /** Return current docBuffer and set docBuffer to null */ def flushDoc: DocComment = { - val ret = if (docBuffer != null) DocComment(docBuffer.toString, docPos) else null - docBuffer = null + val ret = docComment + docComment = null ret } - /** add the given character to the documentation buffer - */ - protected def putDocChar(c: Char) { - if (docBuffer ne null) docBuffer.append(c) - } - protected def foundComment(value: String, start: Int, end: Int) = () protected def foundDocComment(value: String, start: Int, end: Int) = () @@ -236,11 +228,11 @@ trait Scanners extends ScannersCommon { while (!sepRegions.isEmpty && sepRegions.head != RBRACE) sepRegions = sepRegions.tail if (!sepRegions.isEmpty) sepRegions = sepRegions.tail - docBuffer = null + docComment = null case RBRACKET | RPAREN => if (!sepRegions.isEmpty && sepRegions.head == lastToken) sepRegions = sepRegions.tail - docBuffer = null + docComment = null case ARROW => if (!sepRegions.isEmpty && sepRegions.head == lastToken) sepRegions = sepRegions.tail @@ -546,7 +538,7 @@ trait Scanners extends ScannersCommon { nextChar() } while ((ch != CR) && (ch != LF) && (ch != SU)) } else { - docBuffer = null + docComment = null var openComments = 1 appendToComment() nextChar() @@ -554,24 +546,23 @@ trait Scanners extends ScannersCommon { var buildingDocComment = false if (ch == '*' && buildDocs) { buildingDocComment = true - docBuffer = new StringBuilder("/**") } while (openComments > 0) { do { do { if (ch == '/') { - nextChar(); putDocChar(ch); appendToComment() + nextChar(); appendToComment() if (ch == '*') { - nextChar(); putDocChar(ch); appendToComment() + nextChar(); appendToComment() openComments += 1 } } if (ch != '*' && ch != SU) { - nextChar(); putDocChar(ch); appendToComment() + nextChar(); appendToComment() } } while (ch != '*' && ch != SU) while (ch == '*') { - nextChar(); putDocChar(ch); appendToComment() + nextChar(); appendToComment() } } while (ch != '/' && ch != SU) if (ch == '/') nextChar() @@ -1310,7 +1301,8 @@ trait Scanners extends ScannersCommon { } override def foundDocComment(value: String, start: Int, end: Int) { - docPos = new RangePosition(unit.source, start, start, end) + val docPos = new RangePosition(unit.source, start, start, end) + docComment = new DocComment(value, docPos) unit.comment(docPos, value) } } |