diff options
author | Martin Odersky <odersky@gmail.com> | 2013-03-25 21:45:20 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-03-25 21:45:20 +0100 |
commit | 5a039031c165fd9116749f28e9d9e6a0b6d5b0e6 (patch) | |
tree | 0a0b956ad7d384cf31a8d2b7835fe716c33d2834 /src | |
parent | 27a508c50482f4053591ed740f09ecced5bf749b (diff) | |
download | dotty-5a039031c165fd9116749f28e9d9e6a0b6d5b0e6.tar.gz dotty-5a039031c165fd9116749f28e9d9e6a0b6d5b0e6.tar.bz2 dotty-5a039031c165fd9116749f28e9d9e6a0b6d5b0e6.zip |
More fixes to classfile reading.
Can now read entire contents of scala distribution.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Printers.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 21 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/ClassfileParser.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 16 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/transform/Erasure.scala | 8 | ||||
-rw-r--r-- | src/test/showClass.scala | 98 |
7 files changed, 41 insertions, 110 deletions
diff --git a/src/dotty/tools/dotc/core/Printers.scala b/src/dotty/tools/dotc/core/Printers.scala index de9677a3a..e789e7db1 100644 --- a/src/dotty/tools/dotc/core/Printers.scala +++ b/src/dotty/tools/dotc/core/Printers.scala @@ -89,7 +89,7 @@ object Printers { } class PlainPrinter(_ctx: Context) extends Printer { - protected[this] implicit val ctx = _ctx + protected[this] implicit val ctx = _ctx.fresh.withCheckPrefix(false) def controlled(op: => Text): Text = if (ctx.toTextRecursions < maxToTextRecursions) @@ -98,7 +98,7 @@ object Printers { op } catch { case ex: CyclicReference => - "<cycle involving ${ex.denot}>" + s"<cycle involving ${ex.denot}>" } finally { ctx.toTextRecursions -= 1 } diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index dc2502092..fc702b85e 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -570,7 +570,7 @@ object SymDenotations { */ def typeConstructor(implicit ctx: Context): TypeRef = if ((this is PackageClass) || owner.isTerm) symbolicRef - else TypeRef(owner.thisType, name.asTypeName) + else TypeRef(owner.thisType, name.asTypeName).withDenot(this) /** The symbolic typeref representing the type constructor for this type. * @throws ClassCastException is this is not a type diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index c349bc7ba..35225e8e7 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -257,6 +257,20 @@ object Types { pdenot & new JointRefDenotation(NoSymbol, tp.refinedInfo.substThis(tp, pre), Period.allInRun(ctx.runId)) else pdenot + case tp: ThisType => + val d = tp.underlying.findMember(name, pre, excluded) + if (d.exists) d + else + // There is a special case to handle: + // trait Super { this: Sub => private class Inner {} println(this.Inner) } + // class Sub extends Super + // When resolving Super.this.Inner, the normal logic goes to the self type and + // looks for Inner from there. But this fails because Inner is private. + // We fix the problem by having the following fallback case, which links up the + // member in Super instead of Sub. + // As an example of this in the wild, see + // loadClassWithPrivateInnerAndSubSelf in ShowClassTests + tp.cls.symbolicRef.findMember(name, pre, excluded) case tp: TypeProxy => tp.underlying.findMember(name, pre, excluded) case tp: ClassInfo => @@ -868,6 +882,11 @@ object Types { lastDenotation } + private[core] final def withDenot(denot: Denotation): this.type = { + lastDenotation = denot + this + } + protected def loadDenot(implicit ctx: Context) = prefix.member(name) def isType = name.isTypeName @@ -1659,7 +1678,7 @@ object Types { class FatalTypeError(msg: String) extends TypeError(msg) class MalformedType(pre: Type, denot: Denotation) extends FatalTypeError(s"malformed type: $pre is not a legal prefix for $denot") - class CyclicReference(denot: SymDenotation) + class CyclicReference(val denot: SymDenotation) extends FatalTypeError(s"cyclic reference involving $denot") // ----- Misc utilities --------------------------------------------------------- diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index 6b7721213..4981a6f4e 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -229,7 +229,7 @@ class ClassfileParser( case 'L' => def processInner(tp: Type): Type = tp match { case tp @ TypeRef(pre, name) if !(tp.symbol.owner is Flags.ModuleClass) => - TypeRef(pre.widen, name) + TypeRef(processInner(pre.widen), name) case _ => tp } diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index e34209aa1..161034bde 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -364,14 +364,16 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: // return NoSymbol if (tag == EXTMODCLASSref) { - unimplementedTree(s"nested objects") - /* + val module = owner.info.decl(name.toTermName).suchThat(_ is Module) + module.info // force it, as completer does not yet point to module class. + module.symbol.moduleClass + + /* was: val moduleVar = owner.info.decl(name.toTermName.moduleVarName).symbol if (moduleVar.isLazyAccessor) return moduleVar.lazyAccessor.lazyAccessor -*/ - } - NoSymbol + */ + } else NoSymbol } // println(s"read ext symbol $name from ${owner.denot.debugString} in ${classRoot.debugString}") // !!! DEBUG @@ -562,7 +564,9 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot: val tp1 = elim(tp) val isBound = (tp: Type) => boundSyms contains tp.typeSymbol if (tp1 existsPart isBound) { - val tp2 = tp1.subst(boundSyms, boundSyms map (_ => defn.AnyType)) + val anyTypes = boundSyms map (_ => defn.AnyType) + val boundBounds = boundSyms map (_.info.bounds.hi) + val tp2 = tp1.subst(boundSyms, boundBounds).subst(boundSyms, anyTypes) cctx.warning(s"""failure to eliminate existential |original type : $tp forSome {${cctx.dclsText(boundSyms, "; ").show} |reduces to : $tp1 diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala index d10415829..330442408 100644 --- a/src/dotty/tools/dotc/core/transform/Erasure.scala +++ b/src/dotty/tools/dotc/core/transform/Erasure.scala @@ -109,7 +109,13 @@ object Erasure { else paramSignature(sym.info) case tp: RefinedType => val parent = tp.parent - if (parent.dealias.typeSymbol == defn.ArrayClass) paramSignature(eraseArray(tp)) + if (parent.dealias.typeSymbol == defn.ArrayClass) + eraseArray(tp) match { + case tp1: RefinedType if tp1.parent.dealias.typeSymbol == defn.ArrayClass => + paramSignature(tp1.parent) ++ "[]" + case tp1 => + paramSignature(tp1) + } else paramSignature(parent) case tp: TypeProxy => paramSignature(tp.underlying) diff --git a/src/test/showClass.scala b/src/test/showClass.scala deleted file mode 100644 index 823e59d5c..000000000 --- a/src/test/showClass.scala +++ /dev/null @@ -1,98 +0,0 @@ -package test - -import dotty.tools.dotc.core._ -import Contexts._ -import Symbols._, Flags._, Types._, dotty.tools.dotc.util.Texts._ -import Decorators._ - -object showClass { - - private val blackList = List( - // the followig classes cannot be read correctly because they - // contain illegally pickled @throws annotations - // "scala.actors.remote.Proxy", - "scala.actors.remote.Serializer", - "scala.actors.remote.JavaSerializer", - "scala.build.genprod", - "scala.tools.nsc.symtab.classfile.AbstractFileReader", - "scala.remoting.Channel", - "scala.runtime.remoting.RegistryDelegate", - "scala.concurrent.Future", - "scala.concurrent.impl.Future", - "scala.concurrent.Await", - "scala.concurrent.Awaitable", - "scala.concurrent.impl.Promise" - ) - - def showPackage(pkg: TermSymbol)(implicit ctx: Context) { - for (sym <- pkg.info.decls - if sym.owner == pkg.moduleClass && !(sym.name contains '$')) { - println(s"showing $sym in ${pkg.fullName}") - if (sym is Package) showPackage(sym.asTerm) - else if (sym.isClass) showClass(sym) - else if (sym is Module) showClass(sym.moduleClass) - } - } - - def showClass(cls: Symbol)(implicit ctx: Context) = { - val path = cls.fullName.toString - if (blackList contains path) - println(s"blacklisted: $path") - else { - println(s"showing $path -> ${cls.denot}") - val cinfo = cls.info - val infoText: Text = if (cinfo.exists) cinfo.toText else " is missing" - println("======================================") - println((cls.toText ~ infoText).show) - } - } - - def showClasses(path: String)(implicit ctx: Context): Unit = { - println(s"showing file $path") - val cls = ctx.requiredClass(path.toTypeName) - showClass(cls) - showClass(cls.linkedClass) - -/* - val info = cls.info - info match { - case ClassInfo(pre, c, cps, decls, optSelfType) => - println(s"prefix = ${pre.show}") - println(s"self = ${c.show}") - println(s"parents = ${cps.map(_.show).mkString(",")}") - println(s"showClass $path") // !!! DEBUG - println(s"decls = ${decls.show}") - println(s"selftype = ${optSelfType.show}") - println(s"type-params = ${info.typeParams}") - } -*/ - } - - def main(args: Array[String]) = { - val base = Context.theBase - implicit val ctx = base.initialCtx - println(ctx.settings) - base.definitions.init() - - for (arg <- args) showPackage(ctx.requiredPackage(arg)) - -// showPackage(ctx.requiredPackage("scala.reflect")) - - showClasses("scala.reflect.internal.StdCreators") -// showClasses("scala.Array") -// showClasses("scala.math.Ordering") -// showClasses("scala.collection.JavaConversions") -// showClasses("scala.collection.convert.Wrappers") -// showClasses("scala.collection.mutable.WeakHashMap") -// showClasses("scala.collection.GenIterable") -// showClasses("scala.collection.Traversable") -// showClasses("scala.collection.LinearSeqLike") -// showClasses("scala.collection.immutable.List") -// showClasses("scala.collection.convert.Wrappers") -// showClasses("scala.collection.generic.package") -// showClasses("scala.collection.MapLike") -// showClasses("scala.Function1") -// showClasses("dotty.tools.dotc.core.Types") - println("done") - } -}
\ No newline at end of file |