Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions compiler/src/dotty/tools/dotc/util/Positions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import language.implicitConversions
*/
object Positions {

private val StartEndBits = 26
val StartEndMask: Long = (1L << StartEndBits) - 1
private val SyntheticPointDelta = (1 << (64 - StartEndBits * 2)) - 1
private final val StartEndBits = 26
private final val StartEndMask = (1L << StartEndBits) - 1
private final val SyntheticPointDelta = (1 << (64 - StartEndBits * 2)) - 1

/** The maximal representable offset in a position */
val MaxOffset = StartEndMask
private final val MaxOffset = StartEndMask

/** Convert offset `x` to an integer by sign extending the original
* field of `StartEndBits` width.
Expand Down Expand Up @@ -134,18 +134,13 @@ object Positions {
}

/** A synthetic position with given start and end */
def Position(start: Int, end: Int): Position = {
val pos = fromOffsets(start, end, SyntheticPointDelta)
assert(pos.isSynthetic)
pos
}
def Position(start: Int, end: Int): Position =
fromOffsets(start, end, SyntheticPointDelta)

/** A source-derived position with given start, end, and point delta */
def Position(start: Int, end: Int, point: Int): Position = {
val pointDelta = (point - start) max 0
val pos = fromOffsets(start, end, if (pointDelta >= SyntheticPointDelta) 0 else pointDelta)
assert(pos.isSourceDerived)
pos
fromOffsets(start, end, if (pointDelta >= SyntheticPointDelta) 0 else pointDelta)
}

/** A synthetic zero-extent position that starts and ends at given `start`. */
Expand Down