diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/internal/Definitions.scala | 18 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/Types.scala | 19 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/util/Origins.scala (renamed from src/compiler/scala/tools/nsc/util/Origins.scala) | 16 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 37 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Constructors.scala | 30 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 2 |
6 files changed, 61 insertions, 61 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 54c1153f81..900d62476c 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -101,9 +101,9 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val FloatClass = valueCache(tpnme.Float) lazy val DoubleClass = valueCache(tpnme.Double) lazy val BooleanClass = valueCache(tpnme.Boolean) - def Boolean_and = getMember(BooleanClass, nme.ZAND) - def Boolean_or = getMember(BooleanClass, nme.ZOR) - def Boolean_not = getMember(BooleanClass, nme.UNARY_!) + lazy val Boolean_and = getMember(BooleanClass, nme.ZAND) + lazy val Boolean_or = getMember(BooleanClass, nme.ZOR) + lazy val Boolean_not = getMember(BooleanClass, nme.UNARY_!) def ScalaValueClassesNoUnit = ScalaValueClasses filterNot (_ eq UnitClass) def ScalaValueClasses: List[Symbol] = List( @@ -343,12 +343,12 @@ trait Definitions extends reflect.api.StandardDefinitions { // arrays and their members lazy val ArrayModule = getModule("scala.Array") - def ArrayModule_overloadedApply = getMember(ArrayModule, nme.apply) + lazy val ArrayModule_overloadedApply = getMember(ArrayModule, nme.apply) lazy val ArrayClass = getClass("scala.Array") - def Array_apply = getMember(ArrayClass, nme.apply) - def Array_update = getMember(ArrayClass, nme.update) - def Array_length = getMember(ArrayClass, nme.length) - lazy val Array_clone = getMember(ArrayClass, nme.clone_) + lazy val Array_apply = getMember(ArrayClass, nme.apply) + lazy val Array_update = getMember(ArrayClass, nme.update) + lazy val Array_length = getMember(ArrayClass, nme.length) + lazy val Array_clone = getMember(ArrayClass, nme.clone_) // reflection / structural types lazy val SoftReferenceClass = getClass("java.lang.ref.SoftReference") @@ -376,7 +376,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val NoManifest = getModule("scala.reflect.NoManifest") lazy val CodeClass = getClass(sn.Code) lazy val CodeModule = getModule(sn.Code) - def Code_lift = getMember(CodeModule, nme.lift_) + lazy val Code_lift = getMember(CodeModule, nme.lift_) lazy val ScalaSignatureAnnotation = getClass("scala.reflect.ScalaSignature") lazy val ScalaLongSignatureAnnotation = getClass("scala.reflect.ScalaLongSignature") diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 0b6d77db07..998eae0cc1 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -499,6 +499,9 @@ trait Types extends api.Types { self: SymbolTable => * Alternatives of overloaded symbol appear in the order they are declared. */ def decl(name: Name): Symbol = findDecl(name, 0) + + /** A list of all non-private members defined or declared in this type. */ + def nonPrivateDecls: List[Symbol] = decls filter (x => !x.isPrivate) toList /** The non-private defined or declared members with name `name` in this type; * an OverloadedSymbol if several exist, NoSymbol if none exist. @@ -537,6 +540,16 @@ trait Types extends api.Types { self: SymbolTable => */ def nonPrivateMember(name: Name): Symbol = memberBasedOnName(name, BridgeAndPrivateFlags) + + /** All members with the given flags, excluding bridges. + */ + def membersWithFlags(requiredFlags: Long): List[Symbol] = + membersBasedOnFlags(BridgeFlags, requiredFlags) + + /** All non-private members with the given flags, excluding bridges. + */ + def nonPrivateMembersWithFlags(requiredFlags: Long): List[Symbol] = + membersBasedOnFlags(BridgeAndPrivateFlags, requiredFlags) /** The non-private member with given name, admitting members with given flags `admit`. * "Admitting" refers to the fact that members with a PRIVATE, BRIDGE, or VBRIDGE @@ -552,7 +565,10 @@ trait Types extends api.Types { self: SymbolTable => * an OverloadedSymbol if several exist, NoSymbol if none exist */ def nonLocalMember(name: Name): Symbol = memberBasedOnName(name, BridgeFlags | LOCAL) - + + /** Members excluding and requiring the given flags. + * Note: unfortunately it doesn't work to exclude DEFERRED this way. + */ def membersBasedOnFlags(excludedFlags: Long, requiredFlags: Long): List[Symbol] = findMember(nme.ANYNAME, excludedFlags, requiredFlags, false).alternatives @@ -1017,7 +1033,6 @@ trait Types extends api.Types { self: SymbolTable => baseClasses.head.newOverloaded(this, members.toList) } } - /** The existential skolems and existentially quantified variables which are free in this type */ def existentialSkolems: List[Symbol] = { var boundSyms: List[Symbol] = List() diff --git a/src/compiler/scala/tools/nsc/util/Origins.scala b/src/compiler/scala/reflect/internal/util/Origins.scala index f8ba34ae3c..b9985c8f50 100644 --- a/src/compiler/scala/tools/nsc/util/Origins.scala +++ b/src/compiler/scala/reflect/internal/util/Origins.scala @@ -3,10 +3,12 @@ * @author Paul Phillips */ -package scala.tools.nsc -package util +package scala.reflect +package internal.util -import scala.reflect.NameTransformer._ +import NameTransformer._ +import scala.collection.{ mutable, immutable } +import Origins._ /** A debugging class for logging from whence a method is being called. * Say you wanted to discover who was calling phase_= in SymbolTable. @@ -33,10 +35,6 @@ import scala.reflect.NameTransformer._ }}} * */ - -import scala.collection.{ mutable, immutable } -import Origins._ - abstract class Origins { type Rep def newRep(xs: StackSlice): Rep @@ -94,7 +92,9 @@ object Origins { def apply(tag: String, clazz: Class[_]): Origins = apply(tag, new OneLine(clazz)) def apply(tag: String, orElse: => Origins): Origins = { counters find (_.tag == tag) getOrElse { - returning(orElse setTag tag)(counters += _) + val res = orElse setTag tag + counters += res + res } } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index c5624a86aa..e05dd28e00 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -187,6 +187,11 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with val BeanInfoSkipAttr = definitions.getClass("scala.beans.BeanInfoSkip") val BeanDisplayNameAttr = definitions.getClass("scala.beans.BeanDisplayName") val BeanDescriptionAttr = definitions.getClass("scala.beans.BeanDescription") + + final val ExcludedForwarderFlags = { + import Flags._ + ( CASE | SPECIALIZED | LIFTED | PROTECTED | STATIC | BridgeAndPrivateFlags ) + } // Additional interface parents based on annotations and other cues def newParentForAttr(attr: Symbol): Option[Type] = attr match { @@ -1044,32 +1049,20 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with val className = jclass.getName val linkedClass = moduleClass.companionClass val linkedModule = linkedClass.companionSymbol + lazy val conflictingNames: Set[Name] = { + linkedClass.info.members collect { case sym if sym.name.isTermName => sym.name } toSet + } + debuglog("Potentially conflicting names for forwarders: " + conflictingNames) - /** There was a bit of a gordian logic knot here regarding forwarders. - * All we really have to do is exclude certain categories of symbols and - * then all matching names. - */ - def memberNames(sym: Symbol) = sym.info.members map (_.name.toString) toSet - lazy val membersInCommon = - memberNames(linkedModule) intersect memberNames(linkedClass) - - /** Should method `m` get a forwarder in the mirror class? */ - def shouldForward(m: Symbol): Boolean = ( - m.owner != ObjectClass - && m.isMethod - && m.isPublic - && !m.hasFlag(Flags.CASE | Flags.DEFERRED | Flags.SPECIALIZED | Flags.LIFTED) - && !m.isConstructor - && !m.isStaticMember - && !membersInCommon(m.name.toString) - ) - - for (m <- moduleClass.info.nonPrivateMembers) { - if (shouldForward(m)) { + for (m <- moduleClass.info.membersBasedOnFlags(ExcludedForwarderFlags, Flags.METHOD)) { + if (m.isType || m.isDeferred || (m.owner eq ObjectClass) || m.isConstructor) + debuglog("No forwarder for '%s' from %s to '%s'".format(m, className, moduleClass)) + else if (conflictingNames(m.name)) + log("No forwarder for " + m + " due to conflict with " + linkedClass.info.member(m.name)) + else { log("Adding static forwarder for '%s' from %s to '%s'".format(m, className, moduleClass)) addForwarder(jclass, moduleClass, m) } - else debuglog("No forwarder for '%s' from %s to '%s'".format(m, className, moduleClass)) } } diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 342c298e1d..e03f329577 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -254,26 +254,18 @@ abstract class Constructors extends Transform with ast.TreeDSL { for ((accSym, accBody) <- outerAccessors) if (mustbeKept(accSym)) accessTraverser.traverse(accBody) - // Conflicting symbol list from parents: see bug #1960. - // It would be better to mangle the constructor parameter name since - // it can only be used internally, but I think we need more robust name - // mangling before we introduce more of it. - val parentSymbols = Map((for { - p <- impl.parents - if p.symbol.isTrait - sym <- p.symbol.info.nonPrivateMembers - if sym.isGetter && !sym.isOuterField - } yield sym.name -> p): _*) - // Initialize all parameters fields that must be kept. - val paramInits = - for (acc <- paramAccessors if mustbeKept(acc)) yield { - if (parentSymbols contains acc.name) - unit.error(acc.pos, "parameter '%s' requires field but conflicts with %s in '%s'".format( - acc.name, acc.name, parentSymbols(acc.name))) - - copyParam(acc, parameter(acc)) - } + val paramInits = paramAccessors filter mustbeKept map { acc => + // Check for conflicting symbol amongst parents: see bug #1960. + // It would be better to mangle the constructor parameter name since + // it can only be used internally, but I think we need more robust name + // mangling before we introduce more of it. + val conflict = clazz.info.nonPrivateMember(acc.name) filter (s => s.isGetter && !s.isOuterField && s.enclClass.isTrait) + if (conflict ne NoSymbol) + unit.error(acc.pos, "parameter '%s' requires field but conflicts with %s".format(acc.name, conflict.fullLocationString)) + + copyParam(acc, parameter(acc)) + } /** Return a single list of statements, merging the generic class constructor with the * specialized stats. The original statements are retyped in the current class, and diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 78222e203b..8f9cd46611 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -154,7 +154,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R def isJavaVarargsAncestor(clazz: Symbol) = ( clazz.isClass && clazz.isJavaDefined - && (clazz.info.nonPrivateMembers exists isJavaVarArgsMethod) + && (clazz.info.nonPrivateDecls exists isJavaVarArgsMethod) ) /** Add bridges for vararg methods that extend Java vararg methods |