From 7c456cde62f3eb8ad4de21463d4df316c040d52f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 21 Apr 2011 17:21:28 +0000 Subject: Added bridge method capability to compiler. --- src/compiler/scala/tools/nsc/symtab/Definitions.scala | 8 ++++++++ src/compiler/scala/tools/nsc/symtab/Symbols.scala | 4 ---- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 4 ++-- .../scala/tools/nsc/typechecker/SuperAccessors.scala | 7 ++++++- src/library/scala/annotation/bridge.scala | 13 +++++++++++++ src/library/scala/reflect/generic/Scopes.scala | 2 +- src/library/scala/reflect/generic/Symbols.scala | 2 +- src/library/scala/reflect/generic/Types.scala | 7 ++++--- 8 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/library/scala/annotation/bridge.scala diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 1134f0e15f..9f666e008f 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -217,6 +217,7 @@ trait Definitions extends reflect.generic.StandardDefinitions { lazy val ScalaInlineClass = getClass("scala.inline") lazy val ScalaNoInlineClass = getClass("scala.noinline") lazy val SpecializedClass = getClass("scala.specialized") + lazy val BridgeClass = getClass("scala.annotation.bridge") // fundamental reference classes lazy val ScalaObjectClass = getClass("scala.ScalaObject") @@ -607,6 +608,13 @@ trait Definitions extends reflect.generic.StandardDefinitions { result } + def getClassIfDefined(fullname: Name): Symbol = + try { + getClass(fullname) + } catch { + case ex: MissingRequirementError => NoSymbol + } + def getMember(owner: Symbol, name: Name): Symbol = { if (owner == NoSymbol) NoSymbol else owner.info.nonPrivateMember(name) match { diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index bbdbb09a9d..c29edaa75d 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -1579,10 +1579,6 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => */ def nameString: String = decodedName + idString - /** The name of the symbol before decoding, e.g. `$eq$eq` instead of `==`. - */ - def encodedName: String = name.toString - /** If settings.uniqid is set, the symbol's id, else "" */ final def idString: String = if (settings.uniqid.value) "#"+id // +" in "+owner.name+"#"+owner.id // DEBUG diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index d198303d66..3e43b33363 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1506,7 +1506,7 @@ trait Infer { secondTry = true } def improves(sym1: Symbol, sym2: Symbol): Boolean = - sym2 == NoSymbol || + sym2 == NoSymbol || sym2.hasAnnotation(BridgeClass) || { val tp1 = pre.memberType(sym1) val tp2 = pre.memberType(sym2) (tp2 == ErrorType || @@ -1596,7 +1596,7 @@ trait Infer { def improves(sym1: Symbol, sym2: Symbol) = // util.trace("improve "+sym1+sym1.locationString+" on "+sym2+sym2.locationString)( - sym2 == NoSymbol || sym2.isError || + sym2 == NoSymbol || sym2.isError || sym2.hasAnnotation(BridgeClass) || isStrictlyMoreSpecific(followApply(pre.memberType(sym1)), followApply(pre.memberType(sym2)), sym1, sym2) diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 240f0c5f12..280d1b6019 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -184,7 +184,12 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT curTree = tree val body1 = atOwner(currentOwner) { transformTrees(body) } accDefs = accDefs.tail; - treeCopy.Template(tree, parents, self, ownAccDefs.toList ::: body1); + treeCopy.Template(tree, parents, self, ownAccDefs.toList ::: body1) + + case DefDef(_, _, _, _, _, _) if sym.hasAnnotation(definitions.BridgeClass) => + sym.setFlag(BRIDGE) + sym.removeAnnotation(definitions.BridgeClass) + super.transform(tree) case TypeApply(sel @ Select(This(_), name), args) => mayNeedProtectedAccessor(sel, args, false) diff --git a/src/library/scala/annotation/bridge.scala b/src/library/scala/annotation/bridge.scala new file mode 100644 index 0000000000..690370854e --- /dev/null +++ b/src/library/scala/annotation/bridge.scala @@ -0,0 +1,13 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.annotation + +/** If this annotation is present on a method, it will be treated as a bridge method. + */ +private[scala] class bridge extends annotation.StaticAnnotation diff --git a/src/library/scala/reflect/generic/Scopes.scala b/src/library/scala/reflect/generic/Scopes.scala index 9f8a8ecd19..9aff63d958 100755 --- a/src/library/scala/reflect/generic/Scopes.scala +++ b/src/library/scala/reflect/generic/Scopes.scala @@ -4,7 +4,7 @@ package generic trait Scopes { self: Universe => abstract class AbsScope extends Iterable[Symbol] { - def enter(sym: Symbol): Symbol + private[reflect] def enter(sym: Symbol): Symbol } type Scope <: AbsScope diff --git a/src/library/scala/reflect/generic/Symbols.scala b/src/library/scala/reflect/generic/Symbols.scala index 49cf7df1ef..3614bfdeb4 100755 --- a/src/library/scala/reflect/generic/Symbols.scala +++ b/src/library/scala/reflect/generic/Symbols.scala @@ -27,7 +27,7 @@ trait Symbols { self: Universe => /** The name of the symbol before decoding, e.g. `\$eq\$eq` instead of `==`. */ - def encodedName: String + def encodedName: String = name.toString /** The decoded name of the symbol, e.g. `==` instead of `\$eq\$eq`. */ diff --git a/src/library/scala/reflect/generic/Types.scala b/src/library/scala/reflect/generic/Types.scala index 6dcd90e66c..c0eded6ab7 100755 --- a/src/library/scala/reflect/generic/Types.scala +++ b/src/library/scala/reflect/generic/Types.scala @@ -36,20 +36,21 @@ trait Types { self: Universe => } type Type >: Null <: AbsType + type SingletonType >: Null <: Type val NoType: Type val NoPrefix: Type - type ThisType <: Type + type ThisType <: SingletonType val ThisType: ThisTypeExtractor type TypeRef <: Type val TypeRef: TypeRefExtractor - type SingleType <: Type + type SingleType <: SingletonType val SingleType: SingleTypeExtractor - type SuperType <: Type + type SuperType <: SingletonType val SuperType: SuperTypeExtractor type TypeBounds <: Type -- cgit v1.2.3