From 4df9e20349f08ae59aa75e93d5874b87285c9d6a Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Mon, 18 Feb 2013 15:23:07 +0400 Subject: 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. --- .../scala/tools/nsc/ast/parser/Scanners.scala | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src') 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) } } -- cgit v1.2.3