diff options
author | Martin Odersky <odersky@gmail.com> | 2011-08-24 17:04:34 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-08-24 17:04:34 +0000 |
commit | e1a9fd9a7a3092e38915425adbd308b48e48e363 (patch) | |
tree | e454bd48ed20dd979195375d668f89ddaa2a53f3 /src | |
parent | 77175ede13ac1b0b37e82aabdfe091e0ec592b25 (diff) | |
download | scala-e1a9fd9a7a3092e38915425adbd308b48e48e363.tar.gz scala-e1a9fd9a7a3092e38915425adbd308b48e48e363.tar.bz2 scala-e1a9fd9a7a3092e38915425adbd308b48e48e363.zip |
reflection refactoring so that we can now have ...
reflection refactoring so that we can now have a compiler that uses
reflection instead of class files (ReflectGlobal/ReflectMain). Still
needs some debugging to get it to run.
Diffstat (limited to 'src')
11 files changed, 47 insertions, 10 deletions
diff --git a/src/compiler/scala/reflect/runtime/ConversionUtil.scala b/src/compiler/scala/reflect/runtime/ConversionUtil.scala index 47e57a2173..4213506c3b 100644 --- a/src/compiler/scala/reflect/runtime/ConversionUtil.scala +++ b/src/compiler/scala/reflect/runtime/ConversionUtil.scala @@ -7,7 +7,7 @@ import java.lang.reflect.{ Member => jMember, Type => jType, TypeVariable => jTypeVariable, GenericDeclaration} import collection.mutable.HashMap -trait ConversionUtil extends internal.transform.Transforms { self: Universe => +trait ConversionUtil { self: internal.SymbolTable => /** A cache that maintains a bijection between Java reflection type `J` * and Scala reflection type `S`. @@ -56,6 +56,11 @@ trait ConversionUtil extends internal.transform.Transforms { self: Universe => protected val fieldCache = new TwoWayCache[jField, Symbol] protected val tparamCache = new TwoWayCache[jTypeVariable[_], Symbol] + /** the type of this symbol after Scala -> Java transformsi in refChecks, uncurry, erasure + */ + def transformedType(sym: Symbol): Type + + /** The Java class thaty given type compiles to */ def typeToJavaClass(tpe: Type): jClass[_] /** Does method `meth` erase to Java method `jmeth`? diff --git a/src/compiler/scala/reflect/runtime/JavaToScala.scala b/src/compiler/scala/reflect/runtime/JavaToScala.scala index 4406ab74be..b03a956fdb 100644 --- a/src/compiler/scala/reflect/runtime/JavaToScala.scala +++ b/src/compiler/scala/reflect/runtime/JavaToScala.scala @@ -21,7 +21,7 @@ import internal.pickling.UnPickler import collection.mutable.{ HashMap, ListBuffer } import internal.Flags._ -trait JavaToScala extends ConversionUtil { self: Universe => +trait JavaToScala extends ConversionUtil { self: SymbolTable => import definitions._ diff --git a/src/compiler/scala/reflect/runtime/Loaders.scala b/src/compiler/scala/reflect/runtime/Loaders.scala index b508c8e2fe..e25254a6fc 100644 --- a/src/compiler/scala/reflect/runtime/Loaders.scala +++ b/src/compiler/scala/reflect/runtime/Loaders.scala @@ -1,11 +1,11 @@ package scala.reflect package runtime -import internal.Flags +import internal.{Flags, SymbolTable} import java.lang.{Class => jClass, Package => jPackage} -trait Loaders { self: Universe => +trait Loaders { self: SymbolTable => /** The lazy type for root. */ diff --git a/src/compiler/scala/reflect/runtime/ScalaToJava.scala b/src/compiler/scala/reflect/runtime/ScalaToJava.scala index 06ce2cfca2..f6e6087bf9 100644 --- a/src/compiler/scala/reflect/runtime/ScalaToJava.scala +++ b/src/compiler/scala/reflect/runtime/ScalaToJava.scala @@ -6,7 +6,7 @@ import java.lang.reflect.{ Method => jMethod, Constructor => jConstructor, Modifier => jModifier, Field => jField, Member => jMember, Type => jType, Array => jArray, GenericDeclaration} -trait ScalaToJava extends ConversionUtil { self: Universe => +trait ScalaToJava extends ConversionUtil { self: SymbolTable => import definitions._ diff --git a/src/compiler/scala/reflect/runtime/SymbolTable.scala b/src/compiler/scala/reflect/runtime/SymbolTable.scala new file mode 100644 index 0000000000..9e560e0d20 --- /dev/null +++ b/src/compiler/scala/reflect/runtime/SymbolTable.scala @@ -0,0 +1,9 @@ +package scala.reflect +package runtime + +/** + * This symbol table trait fills in the definitions so that class information is obtained by refection. + * It can be used either from the reflexive mirror itself (class Universe), or else from + * a runtime compiler that uses reflection to get a class information (class scala.tools.nsc.ReflectGlobal) + */ +trait SymbolTable extends internal.SymbolTable with JavaToScala with ScalaToJava with Loaders diff --git a/src/compiler/scala/reflect/runtime/Universe.scala b/src/compiler/scala/reflect/runtime/Universe.scala index 5794dfc5da..752b0f13ac 100644 --- a/src/compiler/scala/reflect/runtime/Universe.scala +++ b/src/compiler/scala/reflect/runtime/Universe.scala @@ -8,7 +8,7 @@ import internal.{SomePhase, NoPhase, Phase, TreeGen} * It also provides methods to go from Java members to Scala members, * using the code in JavaConversions. */ -class Universe extends internal.SymbolTable with JavaToScala with ScalaToJava with Loaders { +class Universe extends ReflexiveLoaders with internal.transform.Transforms { type AbstractFileType = AbstractFile diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 592540f450..b502da91fc 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -397,7 +397,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb } with Pickler // phaseName = "refchecks" - object refchecks extends { + object refChecks extends { val global: Global.this.type = Global.this val runsAfter = List[String]("pickler") val runsRightAfter = None @@ -597,7 +597,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb analyzer.typerFactory -> "the meat and potatoes: type the trees", superAccessors -> "add super accessors in traits and nested classes", pickler -> "serialize symbol tables", - refchecks -> "reference/override checking, translate nested objects", + refChecks -> "reference/override checking, translate nested objects", uncurry -> "uncurry, translate function values to anonymous classes", tailCalls -> "replace tail calls by jumps", specializeTypes -> "@specialized-driven class and method specialization", diff --git a/src/compiler/scala/tools/nsc/ReflectGlobal.scala b/src/compiler/scala/tools/nsc/ReflectGlobal.scala new file mode 100644 index 0000000000..3132a9987d --- /dev/null +++ b/src/compiler/scala/tools/nsc/ReflectGlobal.scala @@ -0,0 +1,16 @@ +package scala.tools.nsc + +import reporters.Reporter + +/** A version of Global that uses reflection to get class + * infos, instead of reading class or source files. + */ +class ReflectGlobal(currentSettings: Settings, reporter: Reporter) + extends Global(currentSettings, reporter) with reflect.runtime.SymbolTable { + + override def transformedType(sym: Symbol) = + erasure.transformInfo(sym, + uncurry.transformInfo(sym, + refChecks.transformInfo(sym, sym.info))) + +} diff --git a/src/compiler/scala/tools/nsc/ReflectMain.scala b/src/compiler/scala/tools/nsc/ReflectMain.scala new file mode 100644 index 0000000000..7167f5aa27 --- /dev/null +++ b/src/compiler/scala/tools/nsc/ReflectMain.scala @@ -0,0 +1,7 @@ +package scala.tools.nsc + +object ReflectMain extends Driver { + + override def newCompiler(): Global = new ReflectGlobal(settings, reporter) + +}
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/doc/DocFactory.scala b/src/compiler/scala/tools/nsc/doc/DocFactory.scala index 43363f7961..5a510803ed 100644 --- a/src/compiler/scala/tools/nsc/doc/DocFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/DocFactory.scala @@ -41,7 +41,7 @@ class DocFactory(val reporter: Reporter, val settings: doc.Settings) { processor phasesSet += analyzer.typerFactory phasesSet += superAccessors phasesSet += pickler - phasesSet += refchecks + phasesSet += refChecks } override def forScaladoc = true } diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 914e9c7dbc..03d1c66a36 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -284,7 +284,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT val accName = nme.protName(sym.originalName) val hasArgs = sym.tpe.paramTypes != Nil - val memberType = refchecks.toScalaRepeatedParam(sym.tpe) // fix for #2413 + val memberType = refChecks.toScalaRepeatedParam(sym.tpe) // fix for #2413 // if the result type depends on the this type of an enclosing class, the accessor // has to take an object of exactly this type, otherwise it's more general |