summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/TreeGen.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-07 19:07:01 +0000
committerPaul Phillips <paulp@improving.org>2011-01-07 19:07:01 +0000
commit32e7c243272d7aaae6c662aa3e1716dae61e1117 (patch)
treeec61af7fab062994641da341d5aea4c8aaf67fa3 /src/compiler/scala/tools/nsc/ast/TreeGen.scala
parent148736c3df1fa6463b4b2658c01bcf452a52c224 (diff)
downloadscala-32e7c243272d7aaae6c662aa3e1716dae61e1117.tar.gz
scala-32e7c243272d7aaae6c662aa3e1716dae61e1117.tar.bz2
scala-32e7c243272d7aaae6c662aa3e1716dae61e1117.zip
Great moments in code reuse:
def isRootOrEmptyPackageClass(s: Symbol) = s.isRoot || s.isEmptyPackageClass def isRootOrEmpty = (this == EmptyPackageClass) || (this == RootClass) def isEffectiveRoot = isRoot || isEmptyPackageClass // last one actually not quite identical def isUnqualified(n: Name) = n match { case nme.ROOT | nme.EMPTY_PACKAGE_NAME => true ; case _ => false } I was responsible for at least half of these. Now it's only isEffectiveRoot. Also, I have always found it warty that we have to specify Nothing and Any as upper bounds. I gave the TypeBounds companion object a few obvious methods: def empty: TypeBounds = apply(NothingClass.tpe, AnyClass.tpe) def upper(hi: Type): TypeBounds = apply(NothingClass.tpe, hi) def lower(lo: Type): TypeBounds = apply(lo, AnyClass.tpe) It's a lovable patch. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/TreeGen.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala30
1 files changed, 12 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index 55dfb07c54..978f1e8374 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -28,8 +28,6 @@ abstract class TreeGen {
def productConstr = scalaDot(tpnme.Product)
def serializableConstr = scalaDot(tpnme.Serializable)
- private def isRootOrEmptyPackageClass(s: Symbol) = s.isRoot || s.isEmptyPackageClass
-
def scalaFunctionConstr(argtpes: List[Tree], restpe: Tree, abstractFun: Boolean = false): Tree = {
val cls = if (abstractFun)
mkAttributedRef(AbstractFunctionClass(argtpes.length))
@@ -55,7 +53,7 @@ abstract class TreeGen {
case NoPrefix =>
EmptyTree
case ThisType(clazz) =>
- if (isRootOrEmptyPackageClass(clazz)) EmptyTree
+ if (clazz.isEffectiveRoot) EmptyTree
else mkAttributedThis(clazz)
case SingleType(pre, sym) =>
val qual = mkAttributedStableRef(pre, sym)
@@ -107,9 +105,9 @@ abstract class TreeGen {
def mkAttributedRef(pre: Type, sym: Symbol): Tree = {
val qual = mkAttributedQualifier(pre)
qual match {
- case EmptyTree => mkAttributedIdent(sym)
- case This(clazz) if isRootOrEmptyPackageClass(qual.symbol) => mkAttributedIdent(sym)
- case _ => mkAttributedSelect(qual, sym)
+ case EmptyTree => mkAttributedIdent(sym)
+ case This(clazz) if qual.symbol.isEffectiveRoot => mkAttributedIdent(sym)
+ case _ => mkAttributedSelect(qual, sym)
}
}
@@ -159,24 +157,20 @@ abstract class TreeGen {
Ident(sym.name) setSymbol sym setType sym.tpe
def mkAttributedSelect(qual: Tree, sym: Symbol): Tree = {
- def tpe = qual.tpe
-
- def isUnqualified(n: Name) = n match { case nme.ROOT | nme.EMPTY_PACKAGE_NAME => true ; case _ => false }
- def hasUnqualifiedName(s: Symbol) = s != null && isUnqualified(s.name.toTermName)
- def isInPkgObject(s: Symbol) = s != null && s.owner.isPackageObjectClass && s.owner.owner == tpe.typeSymbol
-
- if (hasUnqualifiedName(qual.symbol))
+ // Tests involving the repl fail without the .isEmptyPackage condition.
+ if (qual.symbol != null && (qual.symbol.isEffectiveRoot || qual.symbol.isEmptyPackage))
mkAttributedIdent(sym)
else {
- val pkgQualifier =
- if (!isInPkgObject(sym)) qual else {
+ val pkgQualifier =
+ if (sym != null && sym.owner.isPackageObjectClass && sym.owner.owner == qual.tpe.typeSymbol) {
val obj = sym.owner.sourceModule
- Select(qual, nme.PACKAGEkw) setSymbol obj setType singleType(tpe, obj)
+ Select(qual, nme.PACKAGEkw) setSymbol obj setType singleType(qual.tpe, obj)
}
- val tree = Select(pkgQualifier, sym)
+ else qual
+ val tree = Select(pkgQualifier, sym)
if (pkgQualifier.tpe == null) tree
- else tree setType (tpe memberType sym)
+ else tree setType (qual.tpe memberType sym)
}
}