From 13182292f247123391eea0e2c62a7fdb6b389c23 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 3 Dec 2010 07:17:46 +0000 Subject: Some html stripping in explicitouter because I ... Some html stripping in explicitouter because I stubbed my toe on some angle brackets. No review. --- .../scala/tools/nsc/transform/ExplicitOuter.scala | 67 ++++++++++++---------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index 3607d517ec..ad07cd908c 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -38,25 +38,32 @@ abstract class ExplicitOuter extends InfoTransform protected def newTransformer(unit: CompilationUnit): Transformer = new ExplicitOuterTransformer(unit) - /** Is given clazz an inner class? */ + /** Is given clazz an inner class? */ private def isInner(clazz: Symbol) = !clazz.isPackageClass && !clazz.outerClass.isStaticOwner - /** Does given clazz define an outer field? */ + private def haveSameOuter(parent: Type, clazz: Symbol) = parent match { + case TypeRef(pre, sym, _) => + val owner = clazz.owner + + sym.isClass && owner.isClass && + owner == sym.owner && + owner.thisType =:= pre + case _ => false + } + + /** Does given clazz define an outer field? */ def hasOuterField(clazz: Symbol) = { - def hasSameOuter(parent: Type) = - parent.typeSymbol.isClass && - clazz.owner.isClass && - clazz.owner == parent.typeSymbol.owner && - parent.prefix =:= clazz.owner.thisType - - isInner(clazz) && !clazz.isTrait && - !(clazz.info.parents.headOption exists hasSameOuter) + val parents = clazz.info.parents + + isInner(clazz) && !clazz.isTrait && { + parents.isEmpty || !haveSameOuter(parents.head, clazz) + } } private def outerField(clazz: Symbol): Symbol = { val result = clazz.info.member(nme.OUTER_LOCAL) - assert(result != NoSymbol, "no outer field in "+clazz+clazz.info.decls+" at "+phase) + assert(result != NoSymbol, "no outer field in "+clazz+" at "+phase) result } @@ -65,7 +72,7 @@ abstract class ExplicitOuter extends InfoTransform * for which the type parameter conforms to Seq, because these answers changed in 2.8. */ def isArraySeqTest(lhs: Type, rhs: Type) = - ArrayClass.tpe <:< lhs.widen && rhs.widen.matchesPattern(SeqClass.tpe) + (ArrayClass.tpe <:< lhs.widen) && (rhs.widen matchesPattern SeqClass.tpe) def outerAccessor(clazz: Symbol): Symbol = { val firstTry = clazz.info.decl(nme.expandedName(nme.OUTER, clazz)) @@ -82,13 +89,13 @@ abstract class ExplicitOuter extends InfoTransform * in a inner non-trait class; * *
  • - * Add a protected $outer field to an inner class which is + * Add a protected $outer field to an inner class which is * not a trait. *
  • *
  • *

    - * Add an outer accessor $outer$$C to every inner class - * with fully qualified name C that is not an interface. + * Add an outer accessor $outer$$C to every inner class + * with fully qualified name C that is not an interface. * The outer accessor is abstract for traits, concrete for other * classes. *

    @@ -167,7 +174,7 @@ abstract class ExplicitOuter extends InfoTransform tp } - /** A base class for transformers that maintain outerParam + /** A base class for transformers that maintain outerParam * values for outer parameters of constructors. * The class provides methods for referencing via outer. */ @@ -209,8 +216,8 @@ abstract class ExplicitOuter extends InfoTransform /** The path *
    `base'.$outer$$C1 ... .$outer$$Cn
    - * which refers to the outer instance of class to of - * value base. The result is typed but not positioned. + * which refers to the outer instance of class to of + * value base. The result is typed but not positioned. * * @param base ... * @param from ... @@ -260,42 +267,42 @@ abstract class ExplicitOuter extends InfoTransform * A constructor of a non-trait inner class gets an outer parameter. *
  • *
  • - * A reference C.this where C refers to an + * A reference C.this where C refers to an * outer class is replaced by a selection - * this.$outer$$C1 ... .$outer$$Cn (@see outerPath) + * this.$outer$$C1 ... .$outer$$Cn (@see outerPath) *
  • *
  • *
  • *
  • * A call to a constructor Q.(args) or Q.$init$(args) where Q != this and * the constructor belongs to a non-static class is augmented by an outer argument. - * E.g. Q.<init>(OUTER, args) where OUTER - * is the qualifier corresponding to the singleton type Q. + * E.g. Q.(OUTER, args) where OUTER + * is the qualifier corresponding to the singleton type Q. *
  • *
  • - * A call to a constructor this.<init>(args) in a - * secondary constructor is augmented to this.<init>(OUTER, args) - * where OUTER is the last parameter of the secondary constructor. + * A call to a constructor this.(args) in a + * secondary constructor is augmented to this.(OUTER, args) + * where OUTER is the last parameter of the secondary constructor. *
  • *
  • - * Remove private modifier from class members M + * Remove private modifier from class members M * that are accessed from an inner class. *
  • *
  • - * Remove protected modifier from class members M + * Remove protected modifier from class members M * that are accessed without a super qualifier accessed from an inner * class or trait. *
  • *
  • - * Remove private and protected modifiers + * Remove private and protected modifiers * from type symbols *
  • *
  • - * Remove private modifiers from members of traits + * Remove private modifiers from members of traits *
  • * *

    - * Note: The whole transform is run in phase explicitOuter.next. + * Note: The whole transform is run in phase explicitOuter.next. *

    */ class ExplicitOuterTransformer(unit: CompilationUnit) extends OuterPathTransformer(unit) { -- cgit v1.2.3