summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-09-07 15:26:26 +0000
committerMartin Odersky <odersky@gmail.com>2011-09-07 15:26:26 +0000
commit8cd3eae681f938ceb64578ffa8bdc69d85c20781 (patch)
tree418201219b5cfa097b31dd8840441ae22c79a39a /src
parent68806429fbd41b6fdfe55da4c124ad1bf2ba8cc4 (diff)
downloadscala-8cd3eae681f938ceb64578ffa8bdc69d85c20781.tar.gz
scala-8cd3eae681f938ceb64578ffa8bdc69d85c20781.tar.bz2
scala-8cd3eae681f938ceb64578ffa8bdc69d85c20781.zip
Another problem solved for reflexive compiler.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/internal/Scopes.scala12
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala2
-rw-r--r--src/compiler/scala/reflect/runtime/Loaders.scala8
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala3
-rw-r--r--src/compiler/scala/tools/nsc/transform/Flatten.scala31
5 files changed, 29 insertions, 27 deletions
diff --git a/src/compiler/scala/reflect/internal/Scopes.scala b/src/compiler/scala/reflect/internal/Scopes.scala
index e71d4147ed..a73b0f4b4f 100644
--- a/src/compiler/scala/reflect/internal/Scopes.scala
+++ b/src/compiler/scala/reflect/internal/Scopes.scala
@@ -74,10 +74,7 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
}
/** Returns a new scope with the same content as this one. */
- def cloneScope: Scope = mkScope(this.toList)
-
- /** Returns a new scope of the same class as this one, with initial elements `decls` */
- def mkScope(decls: List[Symbol] = Nil): Scope = new Scope(decls)
+ def cloneScope: Scope = new Scope(this.toList)
/** is the scope empty? */
override def isEmpty: Boolean = elems eq null
@@ -299,7 +296,7 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
override def foreach[U](p: Symbol => U): Unit = toList foreach p
override def filter(p: Symbol => Boolean): Scope =
- if (!(toList forall p)) mkScope(toList filter p) else this
+ if (!(toList forall p)) new Scope(toList filter p) else this
override def mkString(start: String, sep: String, end: String) =
toList.map(_.defString).mkString(start, sep, end)
@@ -314,6 +311,11 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
/** Create new scope for the members of package `pkg` */
def newPackageScope(pkgClass: Symbol): Scope = new Scope
+ /** Transform scope of members of `owner` using operation `op`
+ * This is overridden by the reflective compiler to avoid creating new scopes for packages
+ */
+ def scopeTransform(owner: Symbol)(op: => Scope): Scope = op
+
def newScopeWith(elems: Symbol*) = {
val scope = newScope
elems foreach scope.enter
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index dab6839353..a6b1e2fb44 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -3411,7 +3411,7 @@ A type's typeSymbol should never be inspected directly.
val elems = scope.toList
val elems1 = mapOver(elems)
if (elems1 eq elems) scope
- else scope.mkScope(elems1)
+ else new Scope(elems1)
}
/** Map this function over given list of symbols */
diff --git a/src/compiler/scala/reflect/runtime/Loaders.scala b/src/compiler/scala/reflect/runtime/Loaders.scala
index 161d06bdb2..bcd80ca557 100644
--- a/src/compiler/scala/reflect/runtime/Loaders.scala
+++ b/src/compiler/scala/reflect/runtime/Loaders.scala
@@ -114,12 +114,10 @@ trait Loaders { self: SymbolTable =>
null
}
}
- override def mkScope(decls: List[Symbol]) = {
- val result = new PackageScope(pkgClass)
- decls foreach (result enter)
- result
- }
}
override def newPackageScope(pkgClass: Symbol) = new PackageScope(pkgClass)
+
+ override def scopeTransform(owner: Symbol)(op: => Scope): Scope =
+ if (owner.isPackageClass) owner.info.decls else op
}
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index 6ec55b2187..4e8e678dc8 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -184,9 +184,10 @@ abstract class AddInterfaces extends InfoTransform {
if (clazz.isTrait) erasedTypeRef(ObjectClass) :: tl
else parents
}
- val decls1 = decls filter (sym =>
+ val decls1 = scopeTransform(clazz) { decls filter (sym =>
if (clazz.isInterface) isInterfaceMember(sym)
else (!sym.isType || sym.isClass))
+ }
//if (!clazz.isPackageClass) System.out.println("Decls of "+clazz+" after explicitOuter = " + decls1);//DEBUG
//if ((parents1 eq parents) && (decls1 eq decls)) tp
diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala
index 62946020eb..b17fd7b9b0 100644
--- a/src/compiler/scala/tools/nsc/transform/Flatten.scala
+++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala
@@ -64,24 +64,25 @@ abstract class Flatten extends InfoTransform {
typeRef(sym.toplevelClass.owner.thisType, sym, Nil)
case ClassInfoType(parents, decls, clazz) =>
var parents1 = parents
- val decls1 = decls.mkScope()
- if (clazz.isPackageClass) {
- atPhase(phase.next)(decls foreach (decls1 enter _))
- }
- else {
- val oldowner = clazz.owner
- atPhase(phase.next)(oldowner.info)
- parents1 = parents mapConserve (this)
+ val decls1 = scopeTransform(clazz) {
+ val decls1 = new Scope()
+ if (clazz.isPackageClass) {
+ atPhase(phase.next)(decls foreach (decls1 enter _))
+ } else {
+ val oldowner = clazz.owner
+ atPhase(phase.next)(oldowner.info)
+ parents1 = parents mapConserve (this)
- for (sym <- decls) {
- if (sym.isTerm && !sym.isStaticModule) {
- decls1 enter sym
- if (sym.isModule)
- sym.moduleClass setFlag LIFTED
+ for (sym <- decls) {
+ if (sym.isTerm && !sym.isStaticModule) {
+ decls1 enter sym
+ if (sym.isModule)
+ sym.moduleClass setFlag LIFTED
+ } else if (sym.isClass)
+ liftSymbol(sym)
}
- else if (sym.isClass)
- liftSymbol(sym)
}
+ decls1
}
ClassInfoType(parents1, decls1, clazz)
case MethodType(params, restp) =>