diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-18 15:29:38 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-18 15:29:38 +0100 |
commit | 5c9433161e116704730693254fdaf161c69cbcb5 (patch) | |
tree | 6c9adc3d7e3b91ee07f7335aac0479df68d67af2 /src/dotty/tools/dotc/core/pickling | |
parent | 2b4a19e80a643dfdf8eea5fa40811f76edb27be3 (diff) | |
download | dotty-5c9433161e116704730693254fdaf161c69cbcb5.tar.gz dotty-5c9433161e116704730693254fdaf161c69cbcb5.tar.bz2 dotty-5c9433161e116704730693254fdaf161c69cbcb5.zip |
Improved position handling.
1. All positions are range position.
2. Improved position API
3. renamed Offset to Coord, and made sure indices cannot be confused with positions.
4. Trees now automatically get positions that enclose their subtree's positions.
5. typed DefTrees contain positions that also enclose their symbol's position.
To make this work well, a symbol's coord should point to the introducing keyword (e.g. def, val, class).
Diffstat (limited to 'src/dotty/tools/dotc/core/pickling')
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/ClassfileParser.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 13 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index 9ba2c46e5..9955d8b56 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -148,7 +148,7 @@ class ClassfileParser( } def parseMember(method: Boolean): Unit = { - val start = new Offset(in.bp) + val start = indexCoord(in.bp) val jflags = in.nextChar val sflags = if (method) FlagTranslation.methodFlags(jflags) @@ -162,7 +162,7 @@ class ClassfileParser( def complete(denot: LazySymDenotation) = { val oldbp = in.bp try { - in.bp = denot.symbol.offset.value + in.bp = denot.symbol.coord.toIndex val sym = denot.symbol val jflags = in.nextChar val isEnum = (jflags & JAVA_ACC_ENUM) != 0 @@ -335,7 +335,7 @@ class ClassfileParser( while (sig(index) != '>') { val tpname = subName(':'.==).toTypeName val s = cctx.newLazySymbol( - owner, tpname, Flags.TypeParam, new TypeParamCompleter(index), new Offset(index)) + owner, tpname, Flags.TypeParam, new TypeParamCompleter(index), indexCoord(index)) tparams = tparams + (tpname -> s) sig2typeBounds(tparams, skiptvs = true) newTParams += s diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 3d8be89b9..e3d08b304 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -68,7 +68,6 @@ object UnPickler { /** Unpickle symbol table information descending from a class and/or module root * from an array of bytes. * @param bytes bytearray from which we unpickle - * @param offset offset from which unpickling starts * @param classroot the top-level class which is unpickled, or NoSymbol if inapplicable * @param moduleroot the top-level module class which is unpickled, or NoSymbol if inapplicable * @param filename filename associated with bytearray, only used for error messages @@ -274,7 +273,7 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: /** Read a symbol, with possible disambiguation */ protected def readDisambiguatedSymbol(p: Symbol => Boolean)(): Symbol = { - val start = new Offset(readIndex) + val start = indexCoord(readIndex) val tag = readByte() val end = readNat() + readIndex def atEnd = readIndex == end @@ -349,7 +348,7 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: def isModuleRoot = (name.toTermName == moduleRoot.name.toTermName) && (owner == moduleRoot.owner) def completeRoot(denot: LazyClassDenotation): Symbol = { - atReadPos(start.value, () => completeLocal(denot)) + atReadPos(start.toIndex, () => completeLocal(denot)) denot.symbol } @@ -370,16 +369,16 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: name1 = name1.expandedName(owner) flags1 |= TypeParamFlags } - cctx.newLazySymbol(owner, name1, flags1, symUnpickler, off = start) + cctx.newLazySymbol(owner, name1, flags1, symUnpickler, coord = start) case CLASSsym => if (isClassRoot) completeRoot(classRoot) else if (isModuleRoot) completeRoot(moduleRoot) - else cctx.newLazyClassSymbol(owner, name.asTypeName, flags, classUnpickler, off = start) + else cctx.newLazyClassSymbol(owner, name.asTypeName, flags, classUnpickler, coord = start) case MODULEsym | VALsym => if (isModuleRoot) { moduleRoot.flags = flags moduleRoot.symbol - } else cctx.newLazySymbol(owner, name.asTermName, flags, symUnpickler, off = start) + } else cctx.newLazySymbol(owner, name.asTermName, flags, symUnpickler, coord = start) case _ => errorBadSignature("bad symbol tag: " + tag) }) @@ -420,7 +419,7 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: assignClassFields(denot, tp, selfType) } } - atReadPos(denot.symbol.offset.value, parseToCompletion) + atReadPos(denot.symbol.coord.toIndex, parseToCompletion) } private object symUnpickler extends SymCompleter { |