summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-05-28 14:12:26 +0000
committerMartin Odersky <odersky@gmail.com>2009-05-28 14:12:26 +0000
commit578d4c671696ec6db3c44dec82bf11d90c65d819 (patch)
tree320874513badd5a748e20c2d67f23ab4f6444377 /src/compiler
parentb7eac378dadaac07aa77a9acfc8a64b212c09e83 (diff)
downloadscala-578d4c671696ec6db3c44dec82bf11d90c65d819.tar.gz
scala-578d4c671696ec6db3c44dec82bf11d90c65d819.tar.bz2
scala-578d4c671696ec6db3c44dec82bf11d90c65d819.zip
more work on rangepositions.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala1
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala35
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala1
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/parser/Parsers.scala31
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala1
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala21
-rw-r--r--src/compiler/scala/tools/nsc/interactive/CompilerControl.scala20
-rwxr-xr-xsrc/compiler/scala/tools/nsc/interactive/ContextTrees.scala129
-rwxr-xr-xsrc/compiler/scala/tools/nsc/interactive/Global.scala29
-rwxr-xr-xsrc/compiler/scala/tools/nsc/javac/JavaParsers.scala1
-rw-r--r--src/compiler/scala/tools/nsc/matching/CodeFactory.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/Flatten.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/LambdaLift.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/LazyVals.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/LiftCode.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/Mixin.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/SampleTransform.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/TailCalls.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala1
-rw-r--r--src/compiler/scala/tools/nsc/util/Position.scala3
34 files changed, 133 insertions, 162 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index 622d229e45..a015cd1cd9 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -16,7 +16,6 @@ abstract class TreeGen {
import global._
import definitions._
- import posAssigner.atPos
def scalaDot(name: Name): Tree =
Select(Ident(nme.scala_) setSymbol ScalaPackage, name)
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 3293b08a39..ae6003a056 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -160,8 +160,14 @@ trait Trees {
def exists(p: Tree => Boolean): Boolean = !find(p).isEmpty
/** The direct children of this tree */
- def children(): Iterator[Tree] =
- productElements filter (_.isInstanceOf[Tree]) map (_.asInstanceOf[Tree])
+ def children(): List[Tree] = {
+ def subtrees(x: Any): List[Tree] = x match {
+ case t: Tree => List(t)
+ case xs: List[_] => xs flatMap subtrees
+ case _ => List()
+ }
+ productElements.toList flatMap subtrees
+ }
override def toString(): String = {
val buffer = new StringWriter()
@@ -341,7 +347,7 @@ trait Trees {
* @return ...
*/
def ClassDef(sym: Symbol, impl: Template): ClassDef =
- posAssigner.atPos(sym.pos) {
+ atPos(sym.pos) {
ClassDef(Modifiers(sym.flags),
sym.name,
sym.typeParams map TypeDef,
@@ -381,7 +387,7 @@ trait Trees {
* @return ...
*/
def ModuleDef(sym: Symbol, impl: Template): ModuleDef =
- posAssigner.atPos(sym.pos) {
+ atPos(sym.pos) {
ModuleDef(Modifiers(sym.flags), sym.name, impl) setSymbol sym
}
@@ -406,7 +412,7 @@ trait Trees {
}
def ValDef(sym: Symbol, rhs: Tree): ValDef =
- posAssigner.atPos(sym.pos) {
+ atPos(sym.pos) {
ValDef(Modifiers(sym.flags), sym.name, TypeTree(sym.tpe), rhs) setSymbol sym
}
@@ -436,7 +442,7 @@ trait Trees {
}
def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef =
- posAssigner.atPos(sym.pos) {
+ atPos(sym.pos) {
assert(sym != NoSymbol)
DefDef(Modifiers(sym.flags),
sym.name,
@@ -465,7 +471,7 @@ trait Trees {
/** A TypeDef node which defines given `sym' with given tight hand side `rhs'. */
def TypeDef(sym: Symbol, rhs: Tree): TypeDef =
- posAssigner.atPos(sym.pos) {
+ atPos(sym.pos) {
TypeDef(Modifiers(sym.flags), sym.name, sym.typeParams map TypeDef, rhs) setSymbol sym
}
@@ -502,7 +508,7 @@ trait Trees {
* @return ...
*/
def LabelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef =
- posAssigner.atPos(sym.pos) {
+ atPos(sym.pos) {
LabelDef(sym.name, params map Ident, rhs) setSymbol sym
}
@@ -598,7 +604,7 @@ trait Trees {
!vparamss1.head.isEmpty && (vparamss1.head.head.mods.flags & IMPLICIT) != 0)
vparamss1 = List() :: vparamss1;
val superRef: Tree = Select(Super(nme.EMPTY.toTypeName, nme.EMPTY.toTypeName), nme.CONSTRUCTOR)
- val superCall = posAssigner.atPos(parents.head.pos) { (superRef /: argss) (Apply) }
+ val superCall = atPos(parents.head.pos) { (superRef /: argss) (Apply) }
List(
DefDef(constrMods, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), Block(lvdefs ::: List(superCall), Literal(()))))
}
@@ -1694,11 +1700,12 @@ trait Trees {
super.traverse(t)
}
}
- def atPos[T <: Tree](pos: Position)(tree: T): T = {
- this.pos = pos
- traverse(tree)
- tree
- }
+ }
+
+ def atPos[T <: Tree](pos: Position)(tree: T): T = {
+ posAssigner.pos = pos
+ posAssigner.traverse(tree)
+ tree
}
class ForeachTreeTraverser(f: Tree => Unit) extends Traverser {
diff --git a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
index 5d6ba35a9f..3118eb6e6d 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
@@ -31,7 +31,6 @@ trait MarkupParsers {self: Parsers =>
}
import global._
- //import posAssigner.atPos
class MarkupParser(parser: UnitParser, presWS: Boolean) /*with scala.xml.parsing.MarkupParser[Tree,Tree] */{
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 4254be02d5..0c434e200d 100755
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -86,7 +86,7 @@ self =>
object symbXMLBuilder extends SymbolicXMLBuilder(treeBuilder, this, true) { // DEBUG choices
val global: self.global.type = self.global
- def freshName(prefix: String): Name = UnitParser.this.freshName(NoPosition, prefix)
+ def freshName(prefix: String): Name = UnitParser.this.freshName(prefix)
}
def xmlLiteral : Tree = xmlp.xLiteral
@@ -112,6 +112,8 @@ self =>
//val unit : CompilationUnit
//import in.ScanPosition
def freshName(pos: Position, prefix: String): Name
+ def freshName(prefix: String): Name = freshName(NoPosition, prefix) // todo get rid of position
+
def o2p(offset: Int): Position
def r2p(start: Int, mid: Int, end: Int): Position
def t2p(tree: Tree): Position = SyntheticPosition(tree)
@@ -124,10 +126,9 @@ self =>
object treeBuilder extends TreeBuilder {
val global: self.global.type = self.global
- def freshName(pos : Position, prefix: String): Name =
- Parser.this.freshName(pos, prefix)
+ def freshName(prefix: String): Name = Parser.this.freshName(prefix)
}
- import treeBuilder._
+ import treeBuilder.{global => _, _}
/** The implicit view parameters of the surrounding class */
var implicitClassViews: List[Tree] = Nil
@@ -378,13 +379,13 @@ self =>
/* ---------- TREE CONSTRUCTION ------------------------------------------- */
def atPos[T <: Tree](offset: Int)(t: T): T =
- posAssigner.atPos(r2p(offset, offset, in.lastOffset))(t)
+ global.atPos(r2p(offset, offset, in.lastOffset))(t)
def atPos[T <: Tree](start: Int, point: Int)(t: T): T =
- posAssigner.atPos(r2p(start, point, in.lastOffset))(t)
+ global.atPos(r2p(start, point, in.lastOffset))(t)
def atPos[T <: Tree](start: Int, point: Int, end: Int)(t: T): T =
- posAssigner.atPos(r2p(start, point, end))(t)
+ global.atPos(r2p(start, point, end))(t)
def atPos[T <: Tree](pos: Position)(t: T): T =
- posAssigner.atPos(pos)(t)
+ global.atPos(pos)(t)
/** Convert tree to formal parameter list
*/
@@ -718,8 +719,9 @@ self =>
val leftAssoc = treeInfo.isLeftAssoc(in.name)
if (mode != InfixMode.FirstOp) checkAssoc(opOffset, in.name, mode == InfixMode.LeftOp)
val op = ident()
+ val tycon = atPos(opOffset) { Ident(op.toTypeName) }
newLineOptWhenFollowing(isTypeIntroToken)
- def mkOp(t1: Tree) = atPos(t.pos.start, opOffset) { AppliedTypeTree(Ident(op.toTypeName), List(t, t1)) }
+ def mkOp(t1: Tree) = atPos(t.pos.start, opOffset) { AppliedTypeTree(tycon, List(t, t1)) }
if (leftAssoc)
infixTypeRest(mkOp(compoundType(isPattern)), isPattern, InfixMode.LeftOp)
else
@@ -845,16 +847,13 @@ self =>
// copy-paste (with change) from def paramType
if (in.token == ARROW) {
in.nextToken()
- atPos(start) {
- AppliedTypeTree(rootScalaDot(nme.BYNAME_PARAM_CLASS_NAME.toTypeName), List(typ()))
- }
+ val tycon = atPos(start) { rootScalaDot(nme.BYNAME_PARAM_CLASS_NAME.toTypeName) }
+ atPos(start) { AppliedTypeTree(tycon, List(typ())) }
} else {
val t = typ()
if (isIdent && in.name == STAR) {
- in.nextToken()
- atPos(start) {
- AppliedTypeTree(rootScalaDot(nme.REPEATED_PARAM_CLASS_NAME.toTypeName), List(t))
- }
+ val tycon = atPos(in.skipToken()) { rootScalaDot(nme.REPEATED_PARAM_CLASS_NAME.toTypeName) }
+ atPos(start) { AppliedTypeTree(tycon, List(t)) }
} else t
}
} else {
diff --git a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala
index abcca4b79c..b2c83ae704 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala
@@ -20,7 +20,6 @@ abstract class SymbolicXMLBuilder(make: TreeBuilder, p: Parsers # Parser, preser
val global: Global
import global._
- import global.posAssigner.atPos
var isPattern: Boolean = _
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
index 8d334a9d78..39bd230212 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -14,10 +14,9 @@ abstract class TreeBuilder {
val global: Global
import global._
- import posAssigner.atPos;
- def freshName(pos : Position, prefix: String): Name
- def freshName(pos : Position): Name = freshName(pos, "x$")
+ def freshName(prefix: String): Name
+ def freshName(): Name = freshName("x$")
def rootId(name: Name) = Select(Ident(nme.ROOTPKG), name)
def rootScalaDot(name: Name): Tree = Select(rootId(nme.scala_) setSymbol definitions.ScalaPackage, name)
@@ -131,7 +130,7 @@ abstract class TreeBuilder {
if (treeInfo.isLeftAssoc(op)) {
Apply(Select(stripParens(left), op.encode), arguments)
} else {
- val x = freshName(posAssigner.pos);
+ val x = freshName()
Block(
List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), stripParens(left))),
Apply(Select(stripParens(right), op.encode), List(Ident(x))))
@@ -158,8 +157,10 @@ abstract class TreeBuilder {
/** Create a tree represeting an assignment &lt;lhs = rhs&gt; */
def makeAssign(lhs: Tree, rhs: Tree): Tree = lhs match {
- case Apply(fn, args) => Apply(Select(fn, nme.update), args ::: List(rhs))
- case _ => Assign(lhs, rhs)
+ case Apply(fn, args) =>
+ Apply(atPos(fn.pos) { Select(fn, nme.update) }, args ::: List(rhs))
+ case _ =>
+ Assign(lhs, rhs)
}
/** A type tree corresponding to (possibly unary) intersection type */
@@ -287,7 +288,7 @@ abstract class TreeBuilder {
def makeBind(pat: Tree): Tree = pat match {
case Bind(_, _) => pat
- case _ => Bind(freshName(pat.pos), pat)
+ case _ => Bind(freshName(), pat)
}
def makeValue(pat: Tree): Tree = pat match {
@@ -373,7 +374,7 @@ abstract class TreeBuilder {
/** Create visitor <x => x match cases> */
def makeVisitor(cases: List[CaseDef], checkExhaustive: Boolean, prefix: String): Tree = {
- val x = freshName(posAssigner.pos, prefix)
+ val x = freshName(prefix)
val sel = if (checkExhaustive) Ident(x) else makeUnchecked(Ident(x))
Function(List(makeSyntheticParam(x)), Match(sel, cases))
}
@@ -411,7 +412,7 @@ abstract class TreeBuilder {
case List((vname, tpt, pos)) =>
List(ValDef(mods, vname, tpt, matchExpr).setPos(pos))
case _ =>
- val tmp = freshName(pat1.pos)
+ val tmp = freshName()
val firstDef = ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC | (mods.flags & LAZY)),
tmp, TypeTree(), matchExpr)
var cnt = 0
@@ -430,7 +431,7 @@ abstract class TreeBuilder {
/** Append implicit view section if for `implicitViews' if nonempty */
def addImplicitViews(owner: Name, vparamss: List[List[ValDef]], implicitViews: List[Tree]): List[List[ValDef]] = {
val mods = Modifiers(if (owner.isTypeName) PARAMACCESSOR | LOCAL | PRIVATE else PARAM)
- def makeViewParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshName(tpt.pos, "view$"), tpt, EmptyTree)
+ def makeViewParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshName("view$"), tpt, EmptyTree)
if (implicitViews.isEmpty) vparamss
else vparamss ::: List(implicitViews map makeViewParam)
}
diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
index f55195973e..479748532b 100644
--- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
+++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
@@ -67,24 +67,4 @@ trait CompilerControl { self: Global =>
class FreshRunReq extends Exception
class ShutdownReq extends Exception
- // ---------------- Helper class -----------------------------
-
- /** A locator for trees with given positions.
- * Given a position `pos`, locator.apply returns
- * the smallest tree that encloses `pos`.
- */
- private class Locator(pos: Position) extends Traverser {
- var last: Tree = _
- def locateIn(root: Tree): Tree = {
- this.last = EmptyTree
- traverse(root)
- this.last
- }
- override def traverse(t: Tree) {
- if (!t.pos.isSynthetic && (t.pos includes pos)) {
- last = t
- super.traverse(t)
- }
- }
- }
}
diff --git a/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala b/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
index b3a290964e..5ed0581bdf 100755
--- a/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
+++ b/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
@@ -8,12 +8,23 @@ trait ContextTrees { self: Global =>
type Context = analyzer.Context
type Contexts = ArrayBuffer[ContextTree]
- class ContextTree(val context: Context, val children: ArrayBuffer[ContextTree]) {
- def this(context: Context) = this(context, new ArrayBuffer[ContextTree])
- def pos: Position = context.tree.pos
+ /** A context tree contains contexts that are indexed by positions.
+ * It satisfies the following properties:
+ * 1. All context come from compiling the same unit.
+ * 2. Child contexts have parent contexts in their outer chain.
+ * 3. The `pos` field of a context is the same as `context.tree.pos`, unless that
+ * position is transparent. In that case, `pos` equals the position of
+ * one of the solid descendants of `context.tree`.
+ * 4. Children of a context have non-overlapping increasining positions.
+ * 5. No context in the tree has a transparent position.
+ */
+ class ContextTree(val pos: Position, val context: Context, val children: ArrayBuffer[ContextTree]) {
+ def this(pos: Position, context: Context) = this(pos, context, new ArrayBuffer[ContextTree])
override def toString = "ContextTree("+pos+", "+children+")"
}
+ /** Optionally return the smallest context taht contains given `pos`, or None if none exists.
+ */
def locateContext(contexts: Contexts, pos: Position): Option[Context] = {
if (contexts.isEmpty) None
else {
@@ -38,61 +49,77 @@ trait ContextTrees { self: Global =>
}
}
+ /** Insert a context at correct position into a buffer of context trees.
+ * If the `context` has a transparent position, add it multiple times
+ * at the positions of all its solid descendant trees.
+ */
def addContext(contexts: Contexts, context: Context) {
val cpos = context.tree.pos
+ if (isTransparent(cpos))
+ for (t <- context.tree.children flatMap solidDescendants)
+ addContext(contexts, context, t.pos)
+ else
+ addContext(contexts, context, cpos)
+ }
+
+ /** Insert a context with non-transparent position `cpos`
+ * at correct position into a buffer of context trees.
+ */
+ def addContext(contexts: Contexts, context: Context, cpos: Position) {
try {
- if (!cpos.isDefined || cpos.isSynthetic) {}
- else if (contexts.isEmpty) contexts += new ContextTree(context)
- else {
- val hi = contexts.length - 1
- if (contexts(hi).pos properlyPrecedes cpos)
- contexts += new ContextTree(context)
- else if (contexts(hi).pos properlyIncludes cpos) // fast path w/o search
- addContext(contexts(hi).children, context)
- else if (cpos properlyPrecedes contexts(0).pos)
- new ContextTree(context) +: contexts
+ if (!cpos.isDefined || cpos.isSynthetic) {}
+ else if (contexts.isEmpty) contexts += new ContextTree(cpos, context)
else {
- def insertAt(idx: Int): Boolean = {
- val oldpos = contexts(idx).pos
- if (oldpos sameRange cpos) {
- contexts(idx) = new ContextTree(context, contexts(idx).children)
- true
- } else if (oldpos includes cpos) {
- addContext(contexts(idx).children, context)
- true
- } else if (cpos includes oldpos) {
- val start = contexts.indexWhere(cpos includes _.pos)
- val last = contexts.lastIndexWhere(cpos includes _.pos)
- contexts(start) = new ContextTree(context, contexts.slice(start, last + 1))
- contexts.remove(start + 1, last - start)
- true
- } else false
- }
- def loop(lo: Int, hi: Int) {
- if (hi - lo > 1) {
- val mid = (lo + hi) / 2
- val midpos = contexts(mid).pos
- if (cpos precedes midpos)
- loop(lo, mid)
- else if (midpos precedes cpos)
- loop(mid, hi)
- } else if (!insertAt(lo) && !insertAt(hi)) {
- val lopos = contexts(lo).pos
- val hipos = contexts(hi).pos
- if ((lopos precedes cpos) && (cpos precedes hipos))
- contexts.insert(hi, new ContextTree(context))
- else
- inform("internal error? skewed positions: "+lopos+" !< "+cpos+" !< "+hipos)
+ val hi = contexts.length - 1
+ if (contexts(hi).pos properlyPrecedes cpos)
+ contexts += new ContextTree(cpos, context)
+ else if (contexts(hi).pos properlyIncludes cpos) // fast path w/o search
+ addContext(contexts(hi).children, context)
+ else if (cpos properlyPrecedes contexts(0).pos)
+ new ContextTree(cpos, context) +: contexts
+ else {
+ def insertAt(idx: Int): Boolean = {
+ val oldpos = contexts(idx).pos
+ if (oldpos sameRange cpos) {
+ contexts(idx) = new ContextTree(cpos, context, contexts(idx).children)
+ true
+ } else if (oldpos includes cpos) {
+ addContext(contexts(idx).children, context)
+ true
+ } else if (cpos includes oldpos) {
+ val start = contexts.indexWhere(cpos includes _.pos)
+ val last = contexts.lastIndexWhere(cpos includes _.pos)
+ contexts(start) = new ContextTree(cpos, context, contexts.slice(start, last + 1))
+ contexts.remove(start + 1, last - start)
+ true
+ } else false
+ }
+ def loop(lo: Int, hi: Int) {
+ if (hi - lo > 1) {
+ val mid = (lo + hi) / 2
+ val midpos = contexts(mid).pos
+ if (cpos precedes midpos)
+ loop(lo, mid)
+ else if (midpos precedes cpos)
+ loop(mid, hi)
+ } else if (!insertAt(lo) && !insertAt(hi)) {
+ val lopos = contexts(lo).pos
+ val hipos = contexts(hi).pos
+ if ((lopos precedes cpos) && (cpos precedes hipos))
+ contexts.insert(hi, new ContextTree(cpos, context))
+ else
+ inform("internal error? skewed positions: "+lopos+" !< "+cpos+" !< "+hipos)
+ }
}
+ loop(0, hi)
}
- loop(0, hi)
}
+ } catch {
+ case ex: Throwable =>
+ println("failure inserting "+cpos+" into "+contexts+"/"+contexts(contexts.length - 1).pos+"/"+
+ (contexts(contexts.length - 1).pos includes cpos))
+ throw ex
}
- } 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/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 44001b4b64..fb448aafc0 100755
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -11,7 +11,11 @@ import scala.tools.nsc.ast._
/** The main class of the presentation compiler in an interactive environment such as an IDE
*/
class Global(settings: Settings, reporter: Reporter)
- extends nsc.Global(settings, reporter) with CompilerControl with ContextTrees with RichCompilationUnits {
+ extends nsc.Global(settings, reporter)
+ with CompilerControl
+ with Positions
+ with ContextTrees
+ with RichCompilationUnits {
self =>
/** A list indicating in which order some units should be typechecked.
@@ -217,29 +221,6 @@ self =>
// ---------------- Helper classes ---------------------------
-
- def validatePositions(tree: Tree) {
- def check(condition: Boolean, msg: => String) {
- if (!condition) {
- println("**** bad positions:")
- println(msg)
- println("================= in =================")
- println(tree)
- }
- }
- def validate(tree: Tree, encltree: Tree, lefttree: Tree) {
- if (encltree.pos.isSynthetic) check(tree.pos.isSynthetic, "synthetic "+encltree+" contains nonsynthetic" + tree)
- check(encltree.pos includes tree.pos, encltree+" does not include "+tree)
- if (lefttree != EmptyTree) check(lefttree.pos precedes tree.pos, lefttree+" does not not precede "+tree)
- var newleft: Tree = EmptyTree
- for (ct <- tree.children) {
- validate(ct, tree, newleft)
- newleft = ct
- }
- }
- validate(tree, tree, EmptyTree)
- }
-
/** A transformer that replaces tree `from` with tree `to` in a given tree */
class TreeReplacer(from: Tree, to: Tree) extends Transformer {
override def transform(t: Tree): Tree = {
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
index f337dac0ac..9539cbac8c 100755
--- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
@@ -16,7 +16,6 @@ import JavaTokens._
trait JavaParsers extends JavaScanners {
val global : Global
import global._
- import posAssigner.atPos
import definitions._
case class JavaOpInfo(operand: Tree, operator: Name, pos: Int)
diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
index 769e739adf..55edc456db 100644
--- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
+++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala
@@ -19,7 +19,6 @@ trait CodeFactory {
import analyzer.Typer;
import definitions._ // standard classes and methods
- import posAssigner.atPos // for filling in tree positions
import Code._
/** Methods to simplify code generation
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index b7418f7827..16821e874f 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -13,7 +13,6 @@ import collection.mutable.{HashMap, ListBuffer}
abstract class AddInterfaces extends InfoTransform {
import global._ // the global environment
import definitions._ // standard classes and methods
- import posAssigner.atPos // for filling in tree positions
/** <p>
* The phase sets <code>lateINTERFACE</code> for non-interface traits
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index f0eea1742b..5339bef080 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -14,7 +14,6 @@ import scala.collection.mutable.{ListBuffer, HashMap}
abstract class CleanUp extends Transform {
import global._
import definitions._
- import posAssigner.atPos
/** the following two members override abstract members in Transform */
val phaseName: String = "cleanup"
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 41137e0798..47256ca8bc 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -16,7 +16,6 @@ import util.TreeSet
abstract class Constructors extends Transform {
import global._
import definitions._
- import posAssigner.atPos
/** the following two members override abstract members in Transform */
val phaseName: String = "constructors"
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 0d4078dc38..e300b81576 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -20,7 +20,6 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
// out erasure still works, uses its own typed methods.
lazy val typerXXX = this.typer
import typerXXX.{typed} // methods to type trees
- import posAssigner.atPos // for filling in tree positions
val phaseName: String = "erasure"
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index db5845c94a..d1fb5d9d82 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -19,7 +19,6 @@ import matching.{TransMatcher, PatternNodes, CodeFactory, ParallelMatching}
abstract class ExplicitOuter extends InfoTransform with TransMatcher with PatternNodes with CodeFactory with ParallelMatching with TypingTransformers {
import global._
import definitions._
- import posAssigner.atPos
/** The following flags may be set by this phase: */
override def phaseNewFlags: Long = notPRIVATE | notPROTECTED | lateFINAL
diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala
index e08d5bd190..4a20175663 100644
--- a/src/compiler/scala/tools/nsc/transform/Flatten.scala
+++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala
@@ -13,7 +13,6 @@ import scala.collection.mutable.{HashMap, ListBuffer}
abstract class Flatten extends InfoTransform {
import global._
import definitions._
- import posAssigner.atPos
/** the following two members override abstract members in Transform */
val phaseName: String = "flatten"
diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
index 52c75fc70e..2c2314f880 100644
--- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
+++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
@@ -16,7 +16,6 @@ abstract class LambdaLift extends InfoTransform {
import global._
import definitions._
import typer.{typed, typedOperator}
- import posAssigner.atPos
/** the following two members override abstract members in Transform */
val phaseName: String = "lambdalift"
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
index ce960068e2..41c3230bff 100644
--- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala
+++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
@@ -9,7 +9,6 @@ abstract class LazyVals extends Transform {
import global._ // the global environment
import definitions._ // standard classes and methods
import typer.{typed, atOwner} // methods to type trees
- import posAssigner.atPos // for filling in tree positions
val phaseName: String = "lazyvals"
diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala
index b17a0efea2..34faa7f683 100644
--- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala
+++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala
@@ -24,7 +24,6 @@ abstract class LiftCode extends Transform with Reifiers {
import global._ // the global environment
import definitions._ // standard classes and methods
import typer.{typed, atOwner} // methods to type trees
- import posAssigner.atPos // for filling in tree positions
val symbols: global.type = global
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala
index f1ee06db45..f5fbafaf7a 100644
--- a/src/compiler/scala/tools/nsc/transform/Mixin.scala
+++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala
@@ -15,7 +15,6 @@ import scala.collection.mutable.HashMap
abstract class Mixin extends InfoTransform {
import global._
import definitions._
- import posAssigner.atPos
/** The name of the phase: */
val phaseName: String = "mixin"
diff --git a/src/compiler/scala/tools/nsc/transform/SampleTransform.scala b/src/compiler/scala/tools/nsc/transform/SampleTransform.scala
index ed39dd183c..b29f82e588 100644
--- a/src/compiler/scala/tools/nsc/transform/SampleTransform.scala
+++ b/src/compiler/scala/tools/nsc/transform/SampleTransform.scala
@@ -14,7 +14,6 @@ abstract class SampleTransform extends Transform {
import global._ // the global environment
import definitions._ // standard classes and methods
import typer.{typed, atOwner} // methods to type trees
- import posAssigner.atPos // for filling in tree positions
/** the following two members override abstract members in Transform */
val phaseName: String = "sample-phase"
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
index b26d3aab39..3df490caac 100644
--- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala
+++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
@@ -20,7 +20,6 @@ abstract class TailCalls extends Transform
import global._ // the global environment
import definitions._ // standard classes and methods
import typer.{typed, atOwner} // methods to type trees
- import posAssigner.atPos // for filling in tree positions
val phaseName: String = "tailcalls"
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 3caaa7ab23..fd853e3ea3 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -34,7 +34,6 @@ import scala.tools.nsc.util.Position
abstract class UnCurry extends InfoTransform with TypingTransformers {
import global._ // the global environment
import definitions._ // standard classes and methods
- import posAssigner.atPos // for filling in tree positions
val phaseName: String = "uncurry"
diff --git a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
index 3ab3ec7b8c..3dede2a699 100644
--- a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
@@ -16,7 +16,6 @@ abstract class DeVirtualize extends InfoTransform with TypingTransformers {
import global._
import definitions._
import typer.{typed, typedOperator, atOwner}
- import posAssigner.atPos
/** the following two members override abstract members in Transform */
val phaseName: String = "devirtualize"
diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
index dde27ece10..f7c8e6d528 100644
--- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
@@ -17,7 +17,6 @@ import symtab.Flags._
trait EtaExpansion { self: Analyzer =>
import global._
- import posAssigner.atPos
object etaExpansion {
def unapply(tree: Tree): Option[(List[ValDef], Tree, List[Tree])] = tree match {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index a828e9165e..81c1acb3be 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -26,7 +26,6 @@ self: Analyzer =>
import global._
import definitions._
- import posAssigner.atPos
final val traceImplicits = false
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index ee892b7b21..9bec522e0c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -18,7 +18,6 @@ trait Infer {
self: Analyzer =>
import global._
import definitions._
- import posAssigner.atPos
// statistics
var normM = 0
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index ad27f3010b..ff60039e1f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -19,7 +19,6 @@ import symtab.Flags._
trait Namers { self: Analyzer =>
import global._
import definitions._
- import posAssigner.atPos
/** Convert to corresponding type parameters all skolems of method parameters
* which appear in `tparams`.
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 37f2c266cd..d4e9136b1a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -43,7 +43,6 @@ abstract class RefChecks extends InfoTransform {
import global._
import definitions._
import typer.{typed, typedOperator, atOwner}
- import posAssigner.atPos
/** the following two members override abstract members in Transform */
val phaseName: String = "refchecks"
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index 3563247e75..7b84b70041 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -26,7 +26,6 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
// inherits abstract value `global' and class `Phase' from Transform
import global._
- import posAssigner.atPos
import typer.typed
/** the following two members override abstract members in Transform */
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 33316d8da0..c3f0365663 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -26,7 +26,6 @@ import util.HashSet
trait Typers { self: Analyzer =>
import global._
import definitions._
- import posAssigner.atPos
private final val printTypings = false
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index 84bddd5f97..4f4c39a0c0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -16,7 +16,6 @@ trait Unapplies { self: Analyzer =>
import global._
import definitions._
- import posAssigner.atPos
/** returns type list for return type of the extraction */
def unapplyTypeList(ufn: Symbol, ufntpe: Type) = {
diff --git a/src/compiler/scala/tools/nsc/util/Position.scala b/src/compiler/scala/tools/nsc/util/Position.scala
index 48343fd948..1063135b8b 100644
--- a/src/compiler/scala/tools/nsc/util/Position.scala
+++ b/src/compiler/scala/tools/nsc/util/Position.scala
@@ -43,6 +43,9 @@ trait Position {
def properlyPrecedes(pos: Position) =
precedes(pos) && start < pos.end
+ def overlaps(pos: Position) =
+ (pos.start <= start && start < pos.end) || (start <= pos.start && pos.start < end)
+
def sameRange(pos: Position) =
isDefined && pos.isDefined && start == pos.start && end == pos.end