diff options
author | Martin Odersky <odersky@gmail.com> | 2013-03-07 17:45:07 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-03-07 17:45:07 +0100 |
commit | 9175fecf86cd798a8f3f23cb95d0028c12d04936 (patch) | |
tree | 8a0b3be35ff50b90958967b0a234255ff04a1672 /src/dotty/tools/dotc/core/Positions.scala | |
parent | 0a6bddc34dbfc9a667c7d63c1dc4de6ae04d7343 (diff) | |
download | dotty-9175fecf86cd798a8f3f23cb95d0028c12d04936.tar.gz dotty-9175fecf86cd798a8f3f23cb95d0028c12d04936.tar.bz2 dotty-9175fecf86cd798a8f3f23cb95d0028c12d04936.zip |
Some polishing of Positions and Trees.
Diffstat (limited to 'src/dotty/tools/dotc/core/Positions.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Positions.scala | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Positions.scala b/src/dotty/tools/dotc/core/Positions.scala index e16f6abe1..5e4673ac4 100644 --- a/src/dotty/tools/dotc/core/Positions.scala +++ b/src/dotty/tools/dotc/core/Positions.scala @@ -11,15 +11,27 @@ object Positions { private val StartEndBits = 26 private val StartEndMask = (1 << StartEndBits) - 1 + private val PointOffsetLimit = 1L << (64 - StartEndBits * 2) class Position(val coords: Long) extends AnyVal { def point: Int = start + (coords >>> (StartEndBits * 2)).toInt def start: Int = (coords & StartEndMask).toInt def end: Int = ((coords >>> StartEndBits) & StartEndMask).toInt + + /** The union of two positions. Tries to keep the point offset of + * the first positon if within range. Otherwise, pointoffset will be 0. + */ def union(that: Position) = - if (this == NoPosition) that - else if (that == NoPosition) this - else Position(this.start min that.start, this.end max that.end) + if (!this.exists) that + else if (!that.exists) this + else { + val start = this.start min that.start + val end = this.end max that.end + var pointOffset = this.point - start + if (pointOffset >= PointOffsetLimit) pointOffset = 0 + Position(start, end, pointOffset) + } + def exists = this != NoPosition } |