From 1f8cf78441d84385734a210b0a5971eae76f46fc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 21 May 2016 13:44:22 +0200 Subject: Let createSymbol return a symbol Compute initialization flags of possibly enclosing traits elsewhere (in indexStats). Cleans up the logic and makes the module more understandable. --- src/dotty/tools/dotc/core/Flags.scala | 3 ++ .../tools/dotc/core/tasty/TreeUnpickler.scala | 47 +++++++++++----------- 2 files changed, 27 insertions(+), 23 deletions(-) (limited to 'src/dotty/tools/dotc') diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index f866621f2..cd660aa46 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -525,6 +525,9 @@ object Flags { /** Either method or lazy */ final val MethodOrLazy = Method | Lazy + /** Either method or lazy or deferred */ + final val MethodOrLazyOrDeferred = Method | Lazy | Deferred + /** Labeled `private` or `final` */ final val PrivateOrFinal = Private | Final diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 2abcce0fa..cd5eb9e50 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -371,10 +371,9 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { } /** Create symbol of definition node and enter in symAtAddr map - * @return the largest subset of {NoInits, PureInterface} that a - * trait owning this symbol can have as flags. + * @return the created symbol */ - def createSymbol()(implicit ctx: Context): FlagSet = { + def createSymbol()(implicit ctx: Context): Symbol = { val start = currentAddr val tag = readByte() val end = readEnd() @@ -434,10 +433,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { sym.completer.withDecls(newScope) forkAt(templateStart).indexTemplateParams()(localContext(sym)) } - if (isClass) NoInits - else if (sym.isType || sym.isConstructor || flags.is(Deferred)) NoInitsInterface - else if (tag == VALDEF) EmptyFlags - else NoInits + sym } /** Read modifier list into triplet of flags, annotations and a privateWithin @@ -504,28 +500,33 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) { (flags, annots.toList, privateWithin) } - /** Create symbols for a definitions in statement sequence between + /** Create symbols for the definitions in the statement sequence between * current address and `end`. * @return the largest subset of {NoInits, PureInterface} that a * trait owning the indexed statements can have as flags. */ def indexStats(end: Addr)(implicit ctx: Context): FlagSet = { - val flagss = - until(end) { - nextByte match { - case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM => - createSymbol() - case IMPORT => - skipTree() - NoInitsInterface - case PACKAGE => - processPackage { (pid, end) => implicit ctx => indexStats(end) } - case _ => - skipTree() - EmptyFlags - } + var initsFlags = NoInitsInterface + while (currentAddr.index < end.index) { + nextByte match { + case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM => + val sym = createSymbol() + if (sym.isTerm && !sym.is(MethodOrLazyOrDeferred)) + initsFlags = EmptyFlags + else if (sym.isClass || + sym.is(Method, butNot = Deferred) && !sym.isConstructor) + initsFlags &= NoInits + case IMPORT => + skipTree() + case PACKAGE => + processPackage { (pid, end) => implicit ctx => indexStats(end) } + case _ => + skipTree() + initsFlags = EmptyFlags } - (NoInitsInterface /: flagss)(_ & _) + } + assert(currentAddr.index == end.index) + initsFlags } /** Process package with given operation `op`. The operation takes as arguments -- cgit v1.2.3