diff options
author | Martin Odersky <odersky@gmail.com> | 2011-11-11 16:08:14 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-11-11 16:08:14 +0000 |
commit | 7918510f4dd1914dfcf156c85e590857e2ac5054 (patch) | |
tree | 1d69a730636ad4ea376928f0a36f9c2f98cd3753 /src | |
parent | f194a29a53d4383bd83f04cced3c382923f224d0 (diff) | |
download | scala-7918510f4dd1914dfcf156c85e590857e2ac5054.tar.gz scala-7918510f4dd1914dfcf156c85e590857e2ac5054.tar.bz2 scala-7918510f4dd1914dfcf156c85e590857e2ac5054.zip |
Small changes to reflection prompted by code re...
Small changes to reflection prompted by code review.
Diffstat (limited to 'src')
5 files changed, 26 insertions, 9 deletions
diff --git a/src/compiler/scala/reflect/runtime/JavaToScala.scala b/src/compiler/scala/reflect/runtime/JavaToScala.scala index b8c8718590..8167588712 100644 --- a/src/compiler/scala/reflect/runtime/JavaToScala.scala +++ b/src/compiler/scala/reflect/runtime/JavaToScala.scala @@ -355,7 +355,8 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable => val sym = sOwner(jclazz).info.decl(newTypeName(jclazz.getSimpleName)) assert(sym.isType, sym+"/"+jclazz+"/"+sOwner(jclazz)+"/"+jclazz.getSimpleName) sym.asInstanceOf[ClassSymbol] - } else if (jclazz.isLocalClass) { // local classes not preserved by unpickling - treat as Java + } else if (jclazz.isLocalClass || invalidClassName(jclazz.getName)) { + // local classes and implementation classes not preserved by unpickling - treat as Java jclassAsScala(jclazz) } else if (jclazz.isArray) { ArrayClass diff --git a/src/compiler/scala/reflect/runtime/Loaders.scala b/src/compiler/scala/reflect/runtime/Loaders.scala index ad6bf34591..eaf3c82d5a 100644 --- a/src/compiler/scala/reflect/runtime/Loaders.scala +++ b/src/compiler/scala/reflect/runtime/Loaders.scala @@ -88,12 +88,12 @@ trait Loaders { self: SymbolTable => } } + /** Is the given name valid for a top-level class? We exclude names with embedded $-signs, because + * these are nested classes or anonymous classes, + */ def invalidClassName(name: Name) = { val dp = name pos '$' - //it's not clear what's the definition of an invalid class name but - //implementation class is certainly a valid class that we would - //like to load (grek) - 0 < dp && dp < (name.length - 1) && !nme.isImplClassName(name) + 0 < dp && dp < (name.length - 1) } class PackageScope(pkgClass: Symbol) extends Scope { diff --git a/src/compiler/scala/reflect/runtime/RuntimeTypes.scala b/src/compiler/scala/reflect/runtime/RuntimeTypes.scala index a1a555c22e..84d02ab7a0 100644 --- a/src/compiler/scala/reflect/runtime/RuntimeTypes.scala +++ b/src/compiler/scala/reflect/runtime/RuntimeTypes.scala @@ -5,6 +5,9 @@ import collection.mutable.ListBuffer trait RuntimeTypes extends Universe with api.RuntimeTypes { + /** To lift path dependent types into reflection, we use InstanceRefSymbols. + * Two of these are equal if they point to the same object reference. Todo: remove + */ case class InstanceRefSymbol(value: AnyRef) extends TermSymbol(NoSymbol, NoPosition, nme.EMPTY) object InstanceRefSymbol extends InstanceRefSymbolExtractor diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala index 694ea6f101..82df75067d 100644 --- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala +++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala @@ -86,7 +86,21 @@ abstract class LiftCode extends Transform with TypingTransformers { } } - /** todo: Treat embedded Code blocks by merging them into containing block + /** + * Given a tree, generate a tree that when exeuted ar tuntime produces the original tree. + * For instance: Given + * + * var x = 1; Code(x + 1) + * + * The `x + 1` expression is reified to + * + * $mr.Apply($mr.Select($mr.Ident($mr.freeVar("x". <Int>, x), "+"), List($mr.Literal($mr.Constant(1)))))) + * + * Or, the term name 'abc' is reified to: + * + * $mr.Apply($mr.Select($mr.Ident("newTermName")), List(Literal(Constant("abc"))))) + * + * todo: Treat embedded Code blocks by merging them into containing block * */ class Reifier() { @@ -105,7 +119,6 @@ abstract class LiftCode extends Transform with TypingTransformers { /** Generate tree of the form * * { val $mr = scala.reflect.runtime.Mirror - * val $memo = new scala.reflext.runtime.Memoizer * $local1 = new TypeSymbol(owner1, NoPosition, name1) * ... * $localN = new TermSymbol(ownerN, NoPositiion, nameN) @@ -196,7 +209,7 @@ abstract class LiftCode extends Transform with TypingTransformers { case None => if (sym == NoSymbol) mirrorSelect("NoSymbol") - else if (sym.isModuleClass) + else if (sym.isModuleClass) Select(reifySymRef(sym.sourceModule), "moduleClass") else if (sym.isStatic && sym.isClass) mirrorCall("staticClass", reify(sym.fullName)) diff --git a/src/library/scala/reflect/Manifest.scala b/src/library/scala/reflect/Manifest.scala index c1f10146c4..9151b0c2a7 100644 --- a/src/library/scala/reflect/Manifest.scala +++ b/src/library/scala/reflect/Manifest.scala @@ -202,7 +202,7 @@ object Manifest { private class SingletonTypeManifest[T <: AnyRef](value: AnyRef) extends Manifest[T] { lazy val erasure = value.getClass - override lazy val tpe = mirror.SingleType(mirror.NoPrefix, InstanceRefSymbol(value)) + override lazy val tpe = mirror.SingleType(mirror.NoPrefix, InstanceRefSymbol(value)) // todo: change to freevar override lazy val toString = value.toString + ".type" } |