summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-10-05 04:29:34 +0000
committerPaul Phillips <paulp@improving.org>2011-10-05 04:29:34 +0000
commit97b41d36b6eaca0d0347590ba408f8c8e2dc0709 (patch)
tree7a90ae705ba3a86e975712746ec5d6ea6eea6251 /src
parentea562b4177eee9f8a00ac9005b7a786d7370563e (diff)
downloadscala-97b41d36b6eaca0d0347590ba408f8c8e2dc0709.tar.gz
scala-97b41d36b6eaca0d0347590ba408f8c8e2dc0709.tar.bz2
scala-97b41d36b6eaca0d0347590ba408f8c8e2dc0709.zip
Massaging type printing and package objects.
Following the 2.5% performance will o' the wisp, and sweeping up the forest floor while I am blithely drawn to my inevitable doom. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/internal/Definitions.scala22
-rw-r--r--src/compiler/scala/reflect/internal/StdNames.scala9
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala24
-rw-r--r--src/compiler/scala/reflect/internal/TreeGen.scala4
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala107
5 files changed, 79 insertions, 87 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala
index 1d0ed2442e..e3b149e0d6 100644
--- a/src/compiler/scala/reflect/internal/Definitions.scala
+++ b/src/compiler/scala/reflect/internal/Definitions.scala
@@ -157,21 +157,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
// private parameter conveniences
private def booltype = BooleanClass.typeConstructor
- private def boolparam = List(booltype)
- private def bytetype = ByteClass.typeConstructor
- private def byteparam = List(bytetype)
- private def shorttype = ShortClass.typeConstructor
- private def shortparam = List(shorttype)
private def inttype = IntClass.typeConstructor
- private def intparam = List(inttype)
- private def longtype = LongClass.typeConstructor
- private def longparam = List(longtype)
- private def floattype = FloatClass.typeConstructor
- private def floatparam = List(floattype)
- private def doubletype = DoubleClass.typeConstructor
- private def doubleparam = List(doubletype)
- private def chartype = CharClass.typeConstructor
- private def charparam = List(chartype)
private def stringtype = StringClass.typeConstructor
// top types
@@ -244,7 +230,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
lazy val PredefModuleClass = PredefModule.moduleClass
// Note: this is not the type alias AnyRef, it's a val defined in Predef
// used by the @specialize annotation.
- def Predef_AnyRef = getMember(PredefModule, tpnme.AnyRef.toTermName)
+ def Predef_AnyRef = getMember(PredefModule, nme.AnyRef)
def Predef_classOf = getMember(PredefModule, nme.classOf)
def Predef_identity = getMember(PredefModule, nme.identity)
def Predef_conforms = getMember(PredefModule, nme.conforms)
@@ -527,8 +513,8 @@ trait Definitions extends reflect.api.StandardDefinitions {
case _ => NoType
}
- def seqType(arg: Type) = typeRef(SeqClass.typeConstructor.prefix, SeqClass, List(arg))
- def arrayType(arg: Type) = typeRef(ArrayClass.typeConstructor.prefix, ArrayClass, List(arg))
+ def seqType(arg: Type) = appliedType(SeqClass.typeConstructor, List(arg))
+ def arrayType(arg: Type) = appliedType(ArrayClass.typeConstructor, List(arg))
def byNameType(arg: Type) = appliedType(ByNameParamClass.typeConstructor, List(arg))
def ClassType(arg: Type) =
@@ -648,7 +634,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
getPackageObject(fullname).companionClass
def getPackageObject(fullname: Name): Symbol =
- getModuleOrClass(fullname.toTermName).info.member(newTermName("package"))
+ getModule(fullname).info member nme.PACKAGE
def getModule(fullname: Name): Symbol =
getModuleOrClass(fullname.toTermName)
diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala
index eb17a13dd4..eca2fd7807 100644
--- a/src/compiler/scala/reflect/internal/StdNames.scala
+++ b/src/compiler/scala/reflect/internal/StdNames.scala
@@ -7,6 +7,7 @@ package scala.reflect
package internal
import scala.collection.immutable
+import NameTransformer.MODULE_SUFFIX_STRING
trait StdNames extends /*reflect.generic.StdNames with*/ NameManglers { self: SymbolTable =>
@@ -94,8 +95,10 @@ trait StdNames extends /*reflect.generic.StdNames with*/ NameManglers { self: Sy
val IMPORT: NameType = "<import>"
val MODULE_VAR_SUFFIX: NameType = "$module"
val ROOT: NameType = "<root>"
+ val PACKAGE: NameType = "package"
- // value types are all used as terms as well
+ // value types (and AnyRef) are all used as terms as well
+ // as (at least) arguments to the @specialize annotation.
final val Boolean: NameType = "Boolean"
final val Byte: NameType = "Byte"
final val Char: NameType = "Char"
@@ -109,7 +112,8 @@ trait StdNames extends /*reflect.generic.StdNames with*/ NameManglers { self: Sy
final val ScalaValueNames: scala.List[NameType] =
scala.List(Byte, Char, Short, Int, Long, Float, Double, Boolean, Unit)
- // types whose companions we utilize
+ // some types whose companions we utilize
+ final val AnyRef: NameType = "AnyRef"
final val Array: NameType = "Array"
final val List: NameType = "List"
final val Seq: NameType = "Seq"
@@ -130,7 +134,6 @@ trait StdNames extends /*reflect.generic.StdNames with*/ NameManglers { self: Sy
final val WILDCARD_STAR: NameType = "_*"
final val Any: NameType = "Any"
- final val AnyRef: NameType = "AnyRef"
final val AnyVal: NameType = "AnyVal"
final val Nothing: NameType = "Nothing"
final val Null: NameType = "Null"
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index aebe4184f4..42265d6969 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -395,9 +395,11 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def isAnonymousFunction = isSynthetic && (name containsName tpnme.ANON_FUN_NAME)
final def isAnonOrRefinementClass = isAnonymousClass || isRefinementClass
- def isPackageObjectOrClass = (name.toTermName == nme.PACKAGEkw) && owner.isPackageClass
- final def isPackageObject = isModule && isPackageObjectOrClass
- final def isPackageObjectClass = isModuleClass && isPackageObjectOrClass
+ // A package object or its module class
+ final def isPackageObjectOrClass = name == nme.PACKAGE || name == tpnme.PACKAGE
+ final def isPackageObject = name == nme.PACKAGE && owner.isPackageClass
+ final def isPackageObjectClass = name == tpnme.PACKAGE && owner.isPackageClass
+
final def isDefinedInPackage = effectiveOwner.isPackageClass
final def isJavaInterface = isJavaDefined && isTrait
final def needsFlatClasses: Boolean = phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass
@@ -405,14 +407,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
// In java.lang, Predef, or scala package/package object
def isInDefaultNamespace = UnqualifiedOwners(effectiveOwner)
- /** If this is a package object or package object class, its owner: otherwise this.
- */
- final def skipPackageObject: Symbol = if (isPackageObjectClass) owner else this
-
/** The owner, skipping package objects.
*/
def effectiveOwner = owner.skipPackageObject
+ /** If this is a package object or its implementing class, its owner: otherwise this.
+ */
+ final def skipPackageObject: Symbol = if (isPackageObjectOrClass) owner else this
+
/** If this is a constructor, its owner: otherwise this.
*/
final def skipConstructor: Symbol = if (isConstructor) owner else this
@@ -451,8 +453,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
info.baseClasses.exists(p => p == SerializableClass || p == JavaSerializableClass)
|| hasAnnotation(SerializableAttr) // last part can be removed, @serializable annotation is deprecated
)
- def isDeprecated = hasAnnotation(DeprecatedAttr)
def hasBridgeAnnotation = hasAnnotation(BridgeClass)
+ def isDeprecated = hasAnnotation(DeprecatedAttr)
def deprecationMessage = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 0)
def deprecationVersion = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 1)
def deprecatedParamName = getAnnotation(DeprecatedNameAttr) flatMap (_ symbolArg 0)
@@ -731,6 +733,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def decodedName: String = stripNameString(NameTransformer.decode(encodedName))
+ /** Either "$" or "" depending on whether this is a module class.
+ */
def moduleSuffix: String = (
if (hasModuleFlag && !isMethod && !isImplClass && !isJavaDefined) nme.MODULE_SUFFIX_STRING
else ""
@@ -763,7 +767,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
private def stripNameString(s: String) =
if (settings.debug.value) s
- else s.replaceAllLiterally(".package", "").trim
+ else s stripSuffix nme.LOCAL_SUFFIX_STRING
/** The encoded full path name of this symbol, where outer names and inner names
* are separated by periods.
@@ -1798,8 +1802,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def hasMeaninglessName = (
isSetterParameter // x$1
|| isClassConstructor // this
- || isPackageObjectOrClass // package
|| isRefinementClass // <refinement>
+ || (name == nme.PACKAGE) // package
)
/** String representation of symbol's simple name.
diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala
index e10a52f0cb..ce7fba6686 100644
--- a/src/compiler/scala/reflect/internal/TreeGen.scala
+++ b/src/compiler/scala/reflect/internal/TreeGen.scala
@@ -177,9 +177,9 @@ abstract class TreeGen {
mkAttributedIdent(sym)
else {
val pkgQualifier =
- if (sym != null && sym.owner.isPackageObjectClass && sym.owner.owner == qual.tpe.typeSymbol) {
+ if (sym != null && sym.owner.isPackageObjectClass && sym.effectiveOwner == qual.tpe.typeSymbol) {
val obj = sym.owner.sourceModule
- Select(qual, nme.PACKAGEkw) setSymbol obj setType singleType(qual.tpe, obj)
+ Select(qual, nme.PACKAGE) setSymbol obj setType singleType(qual.tpe, obj)
}
else qual
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index 43168190a3..d75c7abe13 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -796,7 +796,6 @@ trait Types extends api.Types { self: SymbolTable =>
protected def objectPrefix = "object "
protected def packagePrefix = "package "
-
def trimPrefix(str: String) = str stripPrefix objectPrefix stripPrefix packagePrefix
/** The string representation of this type used as a prefix */
@@ -1220,10 +1219,11 @@ trait Types extends api.Types { self: SymbolTable =>
override def termSymbol = sym
override def prefix: Type = pre
- override def prefixString =
- if (sym.isPackageObjectOrClass) pre.prefixString
- else if (sym.isOmittablePrefix) ""
+ override def prefixString = (
+ if (sym.skipPackageObject.isOmittablePrefix) ""
+ else if (sym.isPackageObjectOrClass) pre.prefixString
else pre.prefixString + sym.nameString + "."
+ )
override def kind = "SingleType"
}
@@ -1241,7 +1241,7 @@ trait Types extends api.Types { self: SymbolTable =>
override def typeSymbol = thistpe.typeSymbol
override def underlying = supertpe
override def prefix: Type = supertpe.prefix
- override def prefixString = thistpe.prefixString.replaceAll("""this\.$""", "super.")
+ override def prefixString = thistpe.prefixString.replaceAll("""\bthis\.$""", "super.")
override def narrow: Type = thistpe.narrow
override def kind = "SuperType"
}
@@ -1999,64 +1999,63 @@ A type's typeSymbol should never be inspected directly.
override def baseClasses: List[Symbol] = thisInfo.baseClasses
// override def isNullable: Boolean = sym.info.isNullable
+ private def preString = (
+ // ensure that symbol is not a local copy with a name coincidence
+ if (!settings.debug.value && shorthands(sym.fullName) && sym.ownerChain.forall(_.isClass)) ""
+ else pre.prefixString
+ )
+ private def argsString = if (args.isEmpty) "" else args.mkString("[", ",", "]")
+ private def refinementString = (
+ if (sym.isStructuralRefinement) (
+ decls filter (sym => sym.isPossibleInRefinement && sym.isPublic)
+ map (_.defString)
+ mkString(" {", "; ", "}")
+ )
+ else ""
+ )
- override def safeToString: String = {
- if (!settings.debug.value) {
- this match {
- case TypeRef(_, RepeatedParamClass, arg :: _) => return arg + "*"
- case TypeRef(_, ByNameParamClass, arg :: _) => return "=> " + arg
- case _ =>
- if (isFunctionType(this)) {
- val targs = normalize.typeArgs
- // Aesthetics: printing Function1 as T => R rather than (T) => R
- val paramlist = targs.init match {
- case Nil => "()"
- case x :: Nil => "" + x
- case xs => xs.mkString("(", ", ", ")")
- }
- return paramlist + " => " + targs.last
- }
- else if (isTupleTypeOrSubtype(this))
- return normalize.typeArgs.mkString("(", ", ", if (hasLength(normalize.typeArgs, 1)) ",)" else ")")
- else if (sym.isAliasType && prefixChain.exists(_.termSymbol.isSynthetic)) {
- val normed = normalize;
- if (normed ne this) return normed.toString
- }
+ private def finishPrefix(rest: String) = (
+ if (sym.isPackageClass) packagePrefix + rest
+ else if (sym.isModuleClass) objectPrefix + rest
+ else if (!sym.isInitialized) rest
+ else if (sym.isAnonymousClass && !phase.erasedTypes)
+ thisInfo.parents.mkString("", " with ", refinementString)
+ else if (sym.isRefinementClass) "" + thisInfo
+ else rest
+ )
+ private def customToString = this match {
+ case TypeRef(_, RepeatedParamClass, arg :: _) => arg + "*"
+ case TypeRef(_, ByNameParamClass, arg :: _) => "=> " + arg
+ case _ =>
+ if (isFunctionType(this)) {
+ val targs = normalize.typeArgs
+ // Aesthetics: printing Function1 as T => R rather than (T) => R
+ val paramlist = targs.init match {
+ case Nil => "()"
+ case x :: Nil => "" + x
+ case xs => xs.mkString("(", ", ", ")")
+ }
+ paramlist + " => " + targs.last
}
- }
- val monopart =
- if (!settings.debug.value &&
- (shorthands contains sym.fullName) &&
- (sym.ownerChain forall (_.isClass))) // ensure that symbol is not a local copy with a name coincidence
- sym.name.toString
+ else if (isTupleTypeOrSubtype(this))
+ normalize.typeArgs.mkString("(", ", ", if (hasLength(normalize.typeArgs, 1)) ",)" else ")")
+ else if (sym.isAliasType && prefixChain.exists(_.termSymbol.isSynthetic) && (normalize ne this))
+ "" + normalize
else
- pre.prefixString + sym.nameString
-
- var str = monopart + (if (args.isEmpty) "" else args.mkString("[", ",", "]"))
- if (sym.isPackageClass)
- packagePrefix + str
- else if (sym.isModuleClass)
- objectPrefix + str
- else if (sym.isAnonymousClass && sym.isInitialized && !settings.debug.value && !phase.erasedTypes)
- thisInfo.parents.mkString(" with ") + {
- if (sym.isStructuralRefinement)
- decls filter (sym => sym.isPossibleInRefinement && sym.isPublic) map (_.defString) mkString("{", "; ", "}")
- else ""
- }
- else if (sym.isRefinementClass && sym.isInitialized)
- thisInfo.toString
- else str
+ ""
+ }
+ override def safeToString = {
+ val custom = if (settings.debug.value) "" else customToString
+ if (custom != "") custom
+ else finishPrefix(preString + sym.nameString + argsString)
}
-
override def prefixString = "" + (
if (settings.debug.value)
super.prefixString
else if (sym.isOmittablePrefix)
""
- else if (sym.isPackageObjectOrClass)
- sym.owner.fullName + "."
- else if (sym.isPackageClass)
- sym.fullName + "."
+ else if (sym.isPackageClass || sym.isPackageObjectOrClass)
+ sym.skipPackageObject.fullName + "."
else if (isStable && nme.isSingletonName(sym.name))
nme.dropSingletonName(sym.name) + "."
else