summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-11-08 22:14:34 +0000
committerPaul Phillips <paulp@improving.org>2011-11-08 22:14:34 +0000
commit173d9473a1ecb6035c369b52a3d7209c34146a10 (patch)
tree9f16a04754eb0e6f3c6e3a3fd9e1cd5851ca06ba /src
parentf9fb5ca997dde7a49fc9d748ca0298befc77b907 (diff)
downloadscala-173d9473a1ecb6035c369b52a3d7209c34146a10.tar.gz
scala-173d9473a1ecb6035c369b52a3d7209c34146a10.tar.bz2
scala-173d9473a1ecb6035c369b52a3d7209c34146a10.zip
Unified binary representations under AbstractFile.
Created MsilFile as a wrapper around MSILType so we can use AbstractFile everywhere. This initial attempt is fairly ham-fisted, since I'm not sure exactly how things are used on the msil side; but it is imposing undue complication on the loaders. Review by magarcia.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/backend/MSILPlatform.scala17
-rw-r--r--src/compiler/scala/tools/nsc/io/MsilFile.scala16
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala11
-rw-r--r--src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala3
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassPath.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/MsilClassPath.scala19
6 files changed, 41 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
index b1daee1f10..65b1fbc229 100644
--- a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
+++ b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
@@ -6,16 +6,16 @@
package scala.tools.nsc
package backend
-import ch.epfl.lamp.compiler.msil.{ Type => MSILType, Attribute => MSILAttribute }
-import util.{ClassPath, MsilClassPath}
+import ch.epfl.lamp.compiler.{ msil => msillib }
+import util.{ ClassPath, MsilClassPath }
import msil.GenMSIL
-import io.AbstractFile
+import io.{ AbstractFile, MsilFile }
trait MSILPlatform extends Platform {
import global._
import definitions.{ ComparatorClass, BoxedNumberClass, getMember }
- type BinaryRepr = MSILType
+ type BinaryRepr = MsilFile
if (settings.verbose.value)
inform("[AssemRefs = " + settings.assemrefs.value + "]")
@@ -38,8 +38,7 @@ trait MSILPlatform extends Platform {
lazy val externalEquals = getMember(ComparatorClass.companionModule, nme.equals_)
def isMaybeBoxed(sym: Symbol) = sym isNonBottomSubClass BoxedNumberClass
- def newClassLoader(bin: MSILType): loaders.SymbolLoader =
- new loaders.MSILTypeLoader(bin)
+ def newClassLoader(bin: MsilFile): loaders.SymbolLoader = new loaders.MsilFileLoader(bin)
/**
* Tells whether a class should be loaded and entered into the package
@@ -49,11 +48,11 @@ trait MSILPlatform extends Platform {
*/
def doLoad(cls: ClassPath[BinaryRepr]#ClassRep): Boolean = {
if (cls.binary.isDefined) {
- val typ = cls.binary.get
+ val typ = cls.binary.get.msilType
if (typ.IsDefined(loaders.clrTypes.SCALA_SYMTAB_ATTR, false)) {
val attrs = typ.GetCustomAttributes(loaders.clrTypes.SCALA_SYMTAB_ATTR, false)
assert(attrs.length == 1, attrs.length)
- val a = attrs(0).asInstanceOf[MSILAttribute]
+ val a = attrs(0).asInstanceOf[msillib.Attribute]
// symtab_constr takes a byte array argument (the pickle), i.e. typ has a pickle.
// otherwise, symtab_default_constr was used, which marks typ as scala-synthetic.
a.getConstructor() == loaders.clrTypes.SYMTAB_CONSTR
@@ -61,6 +60,6 @@ trait MSILPlatform extends Platform {
} else true // always load source
}
- def needCompile(bin: MSILType, src: AbstractFile) =
+ def needCompile(bin: MsilFile, src: AbstractFile) =
false // always use compiled file on .net
}
diff --git a/src/compiler/scala/tools/nsc/io/MsilFile.scala b/src/compiler/scala/tools/nsc/io/MsilFile.scala
new file mode 100644
index 0000000000..69db23923d
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/io/MsilFile.scala
@@ -0,0 +1,16 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2011 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc
+package io
+
+import ch.epfl.lamp.compiler.msil.{ Type => MsilType, _ }
+
+/** This class wraps an MsilType. It exists only so
+ * ClassPath can treat all of JVM/MSIL/bin/src files
+ * uniformly, as AbstractFiles.
+ */
+class MsilFile(val msilType: MsilType) extends VirtualFile(msilType.FullName, msilType.Namespace) {
+} \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
index 7909b5e7a8..da71628097 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -7,15 +7,13 @@ package scala.tools.nsc
package symtab
import java.io.IOException
-import ch.epfl.lamp.compiler.msil.{ Type => MSILType, Attribute => MSILAttribute }
-
import scala.compat.Platform.currentTime
import scala.tools.nsc.util.{ ClassPath }
import classfile.ClassfileParser
import reflect.internal.Flags._
import reflect.internal.MissingRequirementError
import util.Statistics._
-import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.io.{ AbstractFile, MsilFile }
/** This class ...
*
@@ -108,7 +106,7 @@ abstract class SymbolLoaders {
def sourcefile: Option[AbstractFile] = None
/**
- * Description of the resource (ClassPath, AbstractFile, MSILType)
+ * Description of the resource (ClassPath, AbstractFile, MsilFile)
* being processed by this loader
*/
protected def description: String
@@ -239,12 +237,13 @@ abstract class SymbolLoaders {
override def sourcefile: Option[AbstractFile] = classfileParser.srcfile
}
- class MSILTypeLoader(typ: MSILType) extends SymbolLoader {
+ class MsilFileLoader(msilFile: MsilFile) extends SymbolLoader {
+ private def typ = msilFile.msilType
private object typeParser extends clr.TypeParser {
val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global
}
- protected def description = "MSILType "+ typ.FullName + ", assembly "+ typ.Assembly.FullName
+ protected def description = "MsilFile "+ typ.FullName + ", assembly "+ typ.Assembly.FullName
protected def doComplete(root: Symbol) { typeParser.parse(typ, root) }
}
diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
index 154ea89a0d..95ef799720 100644
--- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
@@ -7,6 +7,7 @@ package symtab
package clr
import java.io.IOException
+import io.MsilFile
import ch.epfl.lamp.compiler.msil.{Type => MSILType, Attribute => MSILAttribute, _}
import scala.collection.{ mutable, immutable }
import scala.reflect.internal.pickling.UnPickler
@@ -255,7 +256,7 @@ abstract class TypeParser {
for (ntype <- typ.getNestedTypes() if !(ntype.IsNestedPrivate || ntype.IsNestedAssembly || ntype.IsNestedFamANDAssem)
|| ntype.IsInterface /* TODO why shouldn't nested ifaces be type-parsed too? */ )
{
- val loader = new loaders.MSILTypeLoader(ntype)
+ val loader = new loaders.MsilFileLoader(new MsilFile(ntype))
val nclazz = statics.newClass(NoPosition, ntype.Name.toTypeName)
val nmodule = statics.newModule(NoPosition, ntype.Name)
nclazz.setInfo(loader)
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala
index 1820bd190f..484f809e6f 100644
--- a/src/compiler/scala/tools/nsc/util/ClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -249,7 +249,7 @@ abstract class ClassPath[T] {
// }
/**
- * Represents classes which can be loaded with a ClassfileLoader/MSILTypeLoader
+ * Represents classes which can be loaded with a ClassfileLoader/MsilFileLoader
* and / or a SourcefileLoader.
*/
case class ClassRep(binary: Option[T], source: Option[AbstractFile]) {
diff --git a/src/compiler/scala/tools/nsc/util/MsilClassPath.scala b/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
index a1c310859a..6215506141 100644
--- a/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
@@ -12,9 +12,8 @@ import java.io.File
import java.net.URL
import java.util.StringTokenizer
import scala.util.Sorting
-
import scala.collection.mutable
-import scala.tools.nsc.io.AbstractFile
+import scala.tools.nsc.io.{ AbstractFile, MsilFile }
import ch.epfl.lamp.compiler.msil.{ Type => MSILType, Assembly }
import ClassPath.{ ClassPathContext, isTraitImplementation }
@@ -46,14 +45,14 @@ object MsilClassPath {
new MsilClassPath(assemextdirs.value, assemrefs.value, sourcepath.value, context)
}
- class MsilContext extends ClassPathContext[MSILType] {
- def toBinaryName(rep: MSILType) = rep.Name
+ class MsilContext extends ClassPathContext[MsilFile] {
+ def toBinaryName(rep: MsilFile) = rep.msilType.Name
def newClassPath(assemFile: AbstractFile) = new AssemblyClassPath(MsilClassPath collectTypes assemFile, "", this)
}
- private def assembleEntries(ext: String, user: String, source: String, context: MsilContext): List[ClassPath[MSILType]] = {
+ private def assembleEntries(ext: String, user: String, source: String, context: MsilContext): List[ClassPath[MsilFile]] = {
import ClassPath._
- val etr = new mutable.ListBuffer[ClassPath[MSILType]]
+ val etr = new mutable.ListBuffer[ClassPath[MsilFile]]
val names = new mutable.HashSet[String]
// 1. Assemblies from -Xassem-extdirs
@@ -93,7 +92,7 @@ object MsilClassPath {
// 3. Source path
for (dirName <- expandPath(source, expandStar = false)) {
val file = AbstractFile.getDirectory(dirName)
- if (file ne null) etr += new SourcePath[MSILType](file, context)
+ if (file ne null) etr += new SourcePath[MsilFile](file, context)
}
etr.toList
@@ -104,7 +103,7 @@ import MsilClassPath._
/**
* A assembly file (dll / exe) containing classes and namespaces
*/
-class AssemblyClassPath(types: Array[MSILType], namespace: String, val context: MsilContext) extends ClassPath[MSILType] {
+class AssemblyClassPath(types: Array[MSILType], namespace: String, val context: MsilContext) extends ClassPath[MsilFile] {
def name = {
val i = namespace.lastIndexOf('.')
if (i < 0) namespace
@@ -131,7 +130,7 @@ class AssemblyClassPath(types: Array[MSILType], namespace: String, val context:
while (i < types.length && types(i).Namespace.startsWith(namespace)) {
// CLRTypes used to exclude java.lang.Object and java.lang.String (no idea why..)
if (types(i).Namespace == namespace)
- cls += ClassRep(Some(types(i)), None)
+ cls += ClassRep(Some(new MsilFile(types(i))), None)
i += 1
}
cls.toIndexedSeq
@@ -167,4 +166,4 @@ class AssemblyClassPath(types: Array[MSILType], namespace: String, val context:
* MSILType values.
*/
class MsilClassPath(ext: String, user: String, source: String, context: MsilContext)
-extends MergedClassPath[MSILType](MsilClassPath.assembleEntries(ext, user, source, context), context) { } \ No newline at end of file
+extends MergedClassPath[MsilFile](MsilClassPath.assembleEntries(ext, user, source, context), context) { } \ No newline at end of file