summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala1
-rwxr-xr-xsrc/compiler/scala/tools/nsc/interactive/ContextTrees.scala15
-rw-r--r--src/compiler/scala/tools/nsc/interactive/REPL.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala7
-rw-r--r--src/compiler/scala/tools/nsc/util/Position.scala7
-rw-r--r--src/library/scala/collection/mutable/ArrayBuffer.scala2
-rw-r--r--src/library/scala/util/parsing/CharInputStreamIterator.scala52
-rw-r--r--src/library/scala/util/parsing/Parsers.scala90
-rw-r--r--src/library/scala/util/parsing/SimpleTokenizer.scala68
9 files changed, 27 insertions, 221 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 736c9210ef..5e930bb4fc 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -1787,6 +1787,7 @@ trait Trees {
override def point: Int = original.pos.point
override def end: Int = original.pos.end
override def underlying = original.pos.underlying
+ override def focus = original.pos.focus
}
}
diff --git a/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala b/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
index 8e8d280b4b..b3a290964e 100755
--- a/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
+++ b/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
@@ -11,6 +11,7 @@ trait ContextTrees { self: Global =>
class ContextTree(val context: Context, val children: ArrayBuffer[ContextTree]) {
def this(context: Context) = this(context, new ArrayBuffer[ContextTree])
def pos: Position = context.tree.pos
+ override def toString = "ContextTree("+pos+", "+children+")"
}
def locateContext(contexts: Contexts, pos: Position): Option[Context] = {
@@ -39,15 +40,16 @@ trait ContextTrees { self: Global =>
def addContext(contexts: Contexts, context: Context) {
val cpos = context.tree.pos
+ try {
if (!cpos.isDefined || cpos.isSynthetic) {}
else if (contexts.isEmpty) contexts += new ContextTree(context)
else {
val hi = contexts.length - 1
- if (contexts(hi).pos precedes cpos)
+ if (contexts(hi).pos properlyPrecedes cpos)
contexts += new ContextTree(context)
- else if (contexts(hi).pos includes cpos) // fast path w/o search
+ else if (contexts(hi).pos properlyIncludes cpos) // fast path w/o search
addContext(contexts(hi).children, context)
- else if (cpos precedes contexts(0).pos)
+ else if (cpos properlyPrecedes contexts(0).pos)
new ContextTree(context) +: contexts
else {
def insertAt(idx: Int): Boolean = {
@@ -86,6 +88,11 @@ trait ContextTrees { self: Global =>
loop(0, hi)
}
}
- }
+ } catch {
+ case ex: Throwable =>
+ println("failure inserting "+context.tree.pos+" into "+contexts+"/"+contexts(contexts.length - 1).pos+"/"+
+ (contexts(contexts.length - 1).pos includes cpos))
+ throw ex
+ }}
}
diff --git a/src/compiler/scala/tools/nsc/interactive/REPL.scala b/src/compiler/scala/tools/nsc/interactive/REPL.scala
index 11def170b5..58477dd693 100644
--- a/src/compiler/scala/tools/nsc/interactive/REPL.scala
+++ b/src/compiler/scala/tools/nsc/interactive/REPL.scala
@@ -27,17 +27,19 @@ object REPL extends EvalLoop {
val reloadResult = new SyncVar[Either[Unit, Throwable]]
val typeatResult = new SyncVar[Either[comp.Tree, Throwable]]
loop { line =>
+ println("["+line+"]")
+ println((line split " ").toList)
(line split " ").toList match {
case "reload" :: args =>
comp.askReload(args map toSourceFile, reloadResult)
show(reloadResult)
- case List("typeat", file, line, col1, col2) =>
+ case "typeat" :: file :: line :: col1 :: col2 :: Nil =>
val source = toSourceFile(file)
val linestart = source.lineToOffset(line.toInt)
val pos = comp.rangePos(source, linestart + col1.toInt, linestart + col1.toInt, linestart + col2.toInt)
comp.askTypeAt(pos, typeatResult)
show(typeatResult)
- case List("quit") =>
+ case "quit" :: Nil =>
System.exit(1)
case _ =>
println("unrecongized command")
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 43f6d54be0..3e86181b73 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -28,7 +28,7 @@ self: Analyzer =>
import definitions._
import posAssigner.atPos
- final val traceImplicits = true
+ final val traceImplicits = false
var implicitTime = 0L
var inscopeSucceed = 0L
@@ -55,7 +55,6 @@ self: Analyzer =>
* @return A search result
*/
def inferImplicit(tree: Tree, pt0: Type, reportAmbiguous: Boolean, context: Context): SearchResult = {
- println("infer impl "+pt0)
if (traceImplicits && !tree.isEmpty && !context.undetparams.isEmpty)
println("typing implicit with undetermined type params: "+context.undetparams+"\n"+tree)
val search = new ImplicitSearch(tree, pt0, context.makeImplicit(reportAmbiguous))
@@ -303,7 +302,7 @@ self: Analyzer =>
*/
val wildPt = approximate(pt)
- if (traceImplicits) println("typed impl for "+wildPt+"? "+info.name+":"+info.tpe+"/"+undetParams)
+ //if (traceImplicits) println("typed impl for "+wildPt+"? "+info.name+":"+info.tpe+"/"+undetParams)
if (isPlausiblyCompatible(info.tpe, wildPt) &&
isCompatible(depoly(info.tpe), wildPt) &&
isStable(info.pre)) {
@@ -312,7 +311,7 @@ self: Analyzer =>
if (info.pre == NoPrefix) Ident(info.name)
else Select(gen.mkAttributedQualifier(info.pre), info.name)
}
- if (traceImplicits) println("typed impl?? "+info.name+":"+info.tpe+" ==> "+itree+" with "+wildPt)
+ //if (traceImplicits) println("typed impl?? "+info.name+":"+info.tpe+" ==> "+itree+" with "+wildPt)
def fail(reason: String): SearchResult = {
if (settings.XlogImplicits.value)
inform(itree+" is not a valid implicit value for "+pt0+" because:\n"+reason)
diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala
index 1ebc2df19e..bd60035a5a 100644
--- a/src/compiler/scala/tools/nsc/util/Position.scala
+++ b/src/compiler/scala/tools/nsc/util/Position.scala
@@ -32,11 +32,17 @@ trait Position {
def includes(pos: Position) =
isDefined && pos.isDefined && start <= pos.start && pos.end <= end
+ def properlyIncludes(pos: Position) =
+ includes(pos) && (start < pos.start || pos.end < end)
+
/** Does this position precede that position?
*/
def precedes(pos: Position) =
isDefined && pos.isDefined && end <= pos.start
+ def properlyPrecedes(pos: Position) =
+ precedes(pos) && start < pos.end
+
def sameRange(pos: Position) =
isDefined && pos.isDefined && start == pos.start && end == pos.end
@@ -118,6 +124,7 @@ extends OffsetPosition(source0, point) {
override def pointOrElse(d: Int) = point
override def endOrElse(d: Int) = end
override def focus = OffsetPosition(source0, point)
+ override def toString = "RangePosition("+source0+", "+start+", "+point+", "+end+")"
}
diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala
index 8586ae3fee..ae17cc33b4 100644
--- a/src/library/scala/collection/mutable/ArrayBuffer.scala
+++ b/src/library/scala/collection/mutable/ArrayBuffer.scala
@@ -127,7 +127,7 @@ class ArrayBuffer[A](override protected val initialSize: Int)
* @throws Predef.IndexOutOfBoundsException if <code>n</code> is out of bounds.
*/
override def remove(n: Int, count: Int) {
- if ((n < 0) || (n >= size0))
+ if ((n < 0) || (n >= size0) && count > 0)
throw new IndexOutOfBoundsException(n.toString)
copy(n + count, n, size0 - (n + count))
size0 -= count
diff --git a/src/library/scala/util/parsing/CharInputStreamIterator.scala b/src/library/scala/util/parsing/CharInputStreamIterator.scala
deleted file mode 100644
index 2df83ec4d9..0000000000
--- a/src/library/scala/util/parsing/CharInputStreamIterator.scala
+++ /dev/null
@@ -1,52 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.parsing
-
-
-import java.io.InputStream
-import java.io.{IOException, EOFException}
-
-/** This class ...
- *
- * @author Burak Emir
- * @version 1.0
- *
- * @deprecated use classes from <a target="contentFrame" href="input.html">
- * <code>scala.util.parsing.input</code></a> instead.
- */
-@deprecated
-class CharInputStreamIterator(in: InputStream) extends Iterator[Char] {
-
- private var ch: Int = _
- private var chSet = false
- private var error: IOException = null
-
- private def lookahead() {
- try {
- ch = in.read(); chSet = ch >= 0
- } catch {
- case ex: EOFException => ch = -1
- case ex: IOException => ch = 1; error = ex
- }
- }
-
- def hasNext: Boolean = {
- if (!chSet) lookahead()
- chSet
- }
-
- def next(): Char = {
- if (!chSet) lookahead()
- chSet = false
- ch.asInstanceOf[Char]
- }
-}
diff --git a/src/library/scala/util/parsing/Parsers.scala b/src/library/scala/util/parsing/Parsers.scala
deleted file mode 100644
index 0373081606..0000000000
--- a/src/library/scala/util/parsing/Parsers.scala
+++ /dev/null
@@ -1,90 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.parsing
-
-/** Documentation for this class is currently missing.
- * However, the Scala By Examples document contains a
- * chapter on combinator parsing that comes close.
- *
- * @author Burak Emir
- * @version 1.0
- *
- * @deprecated use <a target="contentFrame" href="combinator/Parsers.html">
- * <code>scala.util.parsing.combinator.Parsers</code></a>
- * instead.
- */
-@deprecated
-abstract class Parsers {
-
- type inputType
-
- abstract class Parser[A] {
-
- type Result = Option[(A, inputType)]
-
- def apply(in: inputType): Result
-
- def filter(pred: A => Boolean) = new Parser[A] {
- def apply(in: inputType): Result = Parser.this.apply(in) match {
- case None => None
- case Some((x, in1)) => if (pred(x)) Some((x, in1)) else None
- }
- }
-
- def map[B](f: A => B) = new Parser[B] {
- def apply(in: inputType): Result = Parser.this.apply(in) match {
- case None => None
- case Some((x, in1)) => Some((f(x), in1))
- }
- }
-
- def flatMap[B](f: A => Parser[B]) = new Parser[B] {
- def apply(in: inputType): Result = Parser.this.apply(in) match {
- case None => None
- case Some((x, in1)) => f(x).apply(in1)
- }
- }
-
- def ||| (p: => Parser[A]) = new Parser[A] {
- def apply(in: inputType): Result = Parser.this.apply(in) match {
- case None => p(in)
- case s => s
- }
- }
-
- def &&& [B](p: => Parser[B]): Parser[B] =
- for (_ <- this; val x <- p) yield x
- }
-
- def not[A](p: Parser[A]) = new Parser[Unit] {
- def apply(in: inputType): Result = p.apply(in) match {
- case None => Some(((), in))
- case Some(_) => None
- }
- }
-
- def succeed[A](x: A) = new Parser[A] {
- def apply(in: inputType): Result = Some((x, in))
- }
-
- def rep[A](p: Parser[A]): Parser[List[A]] =
- rep1(p) ||| succeed(List())
-
- def rep1[A](p: Parser[A]): Parser[List[A]] =
- for (x <- p; val xs <- rep(p)) yield x :: xs
-
- def repWith[A, B](p: Parser[A], sep: Parser[B]): Parser[List[A]] =
- for (x <- p; val xs <- rep(sep &&& p)) yield x :: xs
-
- def opt[A](p: Parser[A]): Parser[List[A]] =
- (for (x <- p) yield List(x)) ||| succeed(List())
-}
diff --git a/src/library/scala/util/parsing/SimpleTokenizer.scala b/src/library/scala/util/parsing/SimpleTokenizer.scala
deleted file mode 100644
index 0b85d237fe..0000000000
--- a/src/library/scala/util/parsing/SimpleTokenizer.scala
+++ /dev/null
@@ -1,68 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.parsing
-
-/** This class ...
- *
- * @author Burak Emir
- * @version 1.0
- *
- * @deprecated use <a target="contentFrame" href="combinator/lexical/StdLexical.html">
- * <code>scala.util.parsing.combinator.lexical.StdLexical</code></a>
- * instead.
- */
-@deprecated
-class SimpleTokenizer(in: Iterator[Char], delimiters: String) extends Iterator[String] {
-
- private def max(x: Int, y: Char): Int = if (x > y) x else y
-
- val tracing = false
-
- private def delimArray: Array[Boolean] = {
- val ds = List.fromString(delimiters)
- val da = new Array[Boolean]((0 /: ds)(max) + 1)
- for (ch <- ds) da(ch) = true
- da
- }
-
- private val isdelim = delimArray
- private def isDelimiter(ch: Int) = ch >= 0 && ch < isdelim.length && isdelim(ch)
-
- private val EOI = -1
-
- private def nextChar(): Int = if (in.hasNext) in.next else EOI
-
- private var ch: Int = nextChar
-
- private val buf = new StringBuilder()
-
- def hasNext: Boolean = ch != EOI
-
- def next(): String = {
- while (ch <= ' ' && ch != EOI) ch = nextChar()
- if (ch == EOI) ""
- else {
- buf setLength 0
- if (isDelimiter(ch)) {
- buf append ch.asInstanceOf[Char]; ch = nextChar()
- } else {
- while (ch > ' ' && ch != EOI && !isDelimiter(ch)) {
- buf append ch.asInstanceOf[Char]
- ch = nextChar()
- }
- }
- if (tracing) Console.println("<" + buf.toString() + ">")
- buf.toString()
- }
- }
-}
-