From 91412ea3d449e8cff88b3c2e79eb16766b3b1476 Mon Sep 17 00:00:00 2001 From: michelou Date: Tue, 12 Sep 2006 11:52:45 +0000 Subject: commented Console.println in transform/Explicit... commented Console.println in transform/ExplicitOuter.scala --- src/compiler/scala/tools/nsc/Global.scala | 38 +++--- src/compiler/scala/tools/nsc/models/Models.scala | 83 +++++------ .../scala/tools/nsc/models/Signatures.scala | 107 ++++++++------- .../scala/tools/nsc/transform/ExplicitOuter.scala | 44 +++--- src/compiler/scala/tools/nsc/transform/Mixin.scala | 151 +++++++++++++-------- 5 files changed, 246 insertions(+), 177 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index c38f462857..385c687eff 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -372,12 +372,12 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable private var curRunId = 0 override def currentRunId = curRunId - private var runCount = 0; + private var runCount = 0 class Run { curRunId = curRunId + 1 assert(curRunId > 0) - //Console.println("starting run: " + id); + //Console.println("starting run: " + id) var currentUnit: CompilationUnit = _ curRun = this val firstPhase = syntaxAnalyzer.newPhase(NoPhase) @@ -482,14 +482,16 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable advancePhase } - if (settings.Xshowcls.value != "") showDef(newTermName(settings.Xshowcls.value), false) - if (settings.Xshowobj.value != "") showDef(newTermName(settings.Xshowobj.value), true) + if (settings.Xshowcls.value != "") + showDef(newTermName(settings.Xshowcls.value), false) + if (settings.Xshowobj.value != "") + showDef(newTermName(settings.Xshowobj.value), true) if (reporter.errors == 0) { assert(stopped || symData.isEmpty, symData.elements.toList) } else { for (val Pair(sym, file) <- symSource.elements) { - sym.reset(new loaders.SourcefileLoader(file)); + sym.reset(new loaders.SourcefileLoader(file)) if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader) } } @@ -613,17 +615,19 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def forCLDC: Boolean = settings.target.value == "cldc" def onlyPresentation = settings.doc.value // position stuff - val positionConfiguration : PositionConfiguration = new PositionConfiguration { - type PositionType = Int; - def coercePosToInt(pos : PositionType) : Int = pos; - def coerceIntToPos(pos : Int) : PositionType = pos; - val NoPos : PositionType = Position.NOPOS; - val FirstPos : PositionType = Position.FIRSTPOS; - } - final type PositionType = positionConfiguration.PositionType; - final val FirstPos = positionConfiguration.FirstPos; - final val NoPos = positionConfiguration.NoPos; - final def coerceIntToPos(pos : Int) : PositionType = positionConfiguration.coerceIntToPos(pos); - implicit final def coercePosToInt(pos : PositionType) : Int = positionConfiguration.coercePosToInt(pos); + val positionConfiguration: PositionConfiguration = new PositionConfiguration { + type PositionType = Int + def coercePosToInt(pos: PositionType): Int = pos + def coerceIntToPos(pos: Int): PositionType = pos + val NoPos: PositionType = Position.NOPOS + val FirstPos: PositionType = Position.FIRSTPOS + } + final type PositionType = positionConfiguration.PositionType + final val FirstPos = positionConfiguration.FirstPos + final val NoPos = positionConfiguration.NoPos + final def coerceIntToPos(pos: Int): PositionType = + positionConfiguration.coerceIntToPos(pos) + implicit final def coercePosToInt(pos: PositionType): Int = + positionConfiguration.coercePosToInt(pos) } diff --git a/src/compiler/scala/tools/nsc/models/Models.scala b/src/compiler/scala/tools/nsc/models/Models.scala index e0ce519290..413ce39fa9 100644 --- a/src/compiler/scala/tools/nsc/models/Models.scala +++ b/src/compiler/scala/tools/nsc/models/Models.scala @@ -9,13 +9,13 @@ package scala.tools.nsc.models import scala.tools.nsc.Global import scala.tools.nsc.util.Position -/** This abstract class.. +/** This abstract class ... * - * @author Sean McDirmid - * #version 1.0 + * @author Sean McDirmid + * @version 1.0 */ abstract class Models { - val global : Global + val global: Global import global._ def acceptPrivate = true @@ -85,9 +85,14 @@ abstract class Models { } } - abstract class Model; + abstract class Model // def textFor(tp : AbsTypeDef) : String = tp.toString() + + /** + * @param tree ... + * @return ... + */ def textFor(tree: Tree): String = { var ret = "" if (tree.symbol != NoSymbol) tree.symbol.name.toString() @@ -129,7 +134,7 @@ abstract class Models { tree = tree0 false } - def replacedBy(tree0: Tree) : Boolean = true + def replacedBy(tree0: Tree): Boolean = true def text: String = textFor(tree) var mods0 = NoMods @@ -137,18 +142,18 @@ abstract class Models { override def toString(): String = tree.toString() - def compare(that : HasTree): Int = { - val idx = KINDS.indexOf(kind); - val jdx = KINDS.indexOf(that.kind); - if (idx != jdx) return idx - jdx; - val result = tree.symbol.nameString.compare(that.tree.symbol.nameString); - if (result != 0) result; + def compare(that: HasTree): Int = { + val idx = KINDS.indexOf(kind) + val jdx = KINDS.indexOf(that.kind) + if (idx != jdx) return idx - jdx + val result = tree.symbol.nameString.compare(that.tree.symbol.nameString) + if (result != 0) result else toString().compare(that.toString()) } def compare [b >: HasTree <% Ordered[b]](that: b): Int = { - if (that.isInstanceOf[HasTree]) { - compare(that.asInstanceOf[HasTree]); - } else -1; + if (that.isInstanceOf[HasTree]) + compare(that.asInstanceOf[HasTree]) + else -1 } def kind = kindOf(tree.symbol) @@ -176,16 +181,15 @@ abstract class Models { import scala.collection.mutable._ class Members extends HashSet[HasTree] - // val members = new Members; + // val members = new Members object members extends Members - def isMember(tree: Tree): Boolean = tree.isInstanceOf[Import] // imports welcome anywhere. def member(tree: Tree, members: List[Tree]): Tree = tree - def update0(members1 : List[Tree]) : Boolean = { - // System.err.println("update0 " + this + " " + members1); + def update0(members1: List[Tree]): Boolean = { + // System.err.println("update0 " + this + " " + members1) if (members1.length == 1 && members1.head.isInstanceOf[PackageDef]) return update0(members1.head.asInstanceOf[PackageDef].stats) @@ -216,9 +220,9 @@ abstract class Models { } // System.err.println("update1 " + this + " " + members + " " + marked) } - val sz = members.size; - members.intersect(marked); - updated = updated || sz < members.size; + val sz = members.size + members.intersect(marked) + updated = updated || sz < members.size // check if anything was removed! updated } @@ -226,7 +230,7 @@ abstract class Models { abstract class MemberMod(parent0: Composite) extends HasTree(parent0) { def treex = tree.asInstanceOf[MemberDef] - def name: Name = { treex.name; } + def name: Name = treex.name override def replacedBy(tree0: Tree): Boolean = if (super.replacedBy(tree0) && tree0.isInstanceOf[MemberDef]) { @@ -255,7 +259,7 @@ abstract class Models { override def update(tree0: Tree): Boolean = { val tree1 = tree0.asInstanceOf[ValOrDefDef] val updated = tree == null || treex.tpe != tree1.tpe - update0(flatten(tree1.rhs, (tree2 : Tree) => isMember(tree2))) + update0(flatten(tree1.rhs, (tree2: Tree) => isMember(tree2))) super.update(tree0) || updated } } @@ -280,7 +284,8 @@ abstract class Models { } else false } - abstract class ImplMod(parent0: Composite) extends MemberComposite(parent0) with HasClassObjects { + abstract class ImplMod(parent0: Composite) + extends MemberComposite(parent0) with HasClassObjects { def treey = tree.asInstanceOf[ImplDef] override def replacedBy(tree0: Tree): Boolean = super.replacedBy(tree0) && tree0.isInstanceOf[ImplDef] @@ -289,7 +294,7 @@ abstract class Models { (acceptPrivate || !tree.asInstanceOf[ValOrDefDef].mods.isPrivate) /* && !tree.asInstanceOf[ValOrDefDef].mods.isPrivate */ /* && !tree.asInstanceOf[ValOrDefDef].mods.isAccessor */) || - tree.isInstanceOf[AliasTypeDef]); + tree.isInstanceOf[AliasTypeDef]) override def member(tree: Tree, members: List[Tree]): Tree = { val tree0 = if (tree.isInstanceOf[DefDef]) { @@ -307,8 +312,9 @@ abstract class Models { def sym = tree0.symbol if (tree0 == null || sym.pos == NoPos) null else if (!acceptPrivate && - tree0.isInstanceOf[ValOrDefDef] && tree0.asInstanceOf[ValOrDefDef].mods.isPrivate) null; - else tree0; + tree0.isInstanceOf[ValOrDefDef] && + tree0.asInstanceOf[ValOrDefDef].mods.isPrivate) null + else tree0 } def children(tree0: Tree): List[Tree] = @@ -320,7 +326,7 @@ abstract class Models { } } - class ClassMod(parent0: Composite) extends ImplMod(parent0) { + class ClassMod(parent0: Composite) extends ImplMod(parent0) { def treez = tree.asInstanceOf[ClassDef] override def replacedBy(tree0: Tree): Boolean = super.replacedBy(tree0) && tree0.isInstanceOf[ClassDef] @@ -341,29 +347,28 @@ abstract class Models { override def replacedBy(tree0: Tree): Boolean = super.replacedBy(tree0) && tree0.isInstanceOf[AbsTypeDef] } - def SourceMod(original : CompilationUnit) = new SourceMod(original); + def SourceMod(original: CompilationUnit) = new SourceMod(original) - class SourceMod(val original : CompilationUnit) extends Composite with HasClassObjects { - update(original); + class SourceMod(val original: CompilationUnit) extends Composite with HasClassObjects { + update(original) //var listener : Listener = null; - def update(unit : CompilationUnit) = unit.body match { - case pdef : PackageDef => try { - update0(pdef.stats); + def update(unit: CompilationUnit) = unit.body match { + case pdef: PackageDef => try { + update0(pdef.stats) } catch { - case e : Error => members.clear; update0(pdef.stats); + case e: Error => members.clear; update0(pdef.stats) } case _ => } - override def isMember(tree: Tree): Boolean = super.isMember(tree) || tree.isInstanceOf[Import] } def flatten0(exprs: List[Tree], filter: (Tree) => Boolean): List[Tree] = - for (val expr <- exprs; val t: Tree <- flatten(expr,filter)) yield t; + for (val expr <- exprs; val t: Tree <- flatten(expr,filter)) yield t - def flatten(expr : Tree, filter: (Tree) => Boolean) : List[Tree] = + def flatten(expr: Tree, filter: (Tree) => Boolean): List[Tree] = if (filter(expr)) expr :: Nil; else expr match { case Block(stats, last) => flatten0(stats, filter) ::: flatten(last, filter) diff --git a/src/compiler/scala/tools/nsc/models/Signatures.scala b/src/compiler/scala/tools/nsc/models/Signatures.scala index 43f5d3e73e..b394edc3a4 100644 --- a/src/compiler/scala/tools/nsc/models/Signatures.scala +++ b/src/compiler/scala/tools/nsc/models/Signatures.scala @@ -6,64 +6,79 @@ package scala.tools.nsc.models -import scala.collection.mutable.{HashMap,HashSet} +import scala.collection.mutable.{HashMap, HashSet} import scala.tools.nsc.{Global => Compiler} -import scala.tools.nsc.symtab.{Flags,Names} -import scala.tools.nsc.util.{NameTransformer,Position,SourceFile} +import scala.tools.nsc.symtab.{Flags, Names} +import scala.tools.nsc.util.{NameTransformer, Position, SourceFile} +/** This class ... + * + * @author Sean McDirmid + * @version 1.0 + */ class Signatures(val compiler: Compiler) { - import compiler._; + import compiler._ - class Signature(val name : String, val children : List[Signature]) { - def asString : String = name + "[" + asString0(children) + "]"; + class Signature(val name: String, val children: List[Signature]) { + def asString: String = name + "[" + asString0(children) + "]" } - def sort(sigs : List[Signature]) = - sigs.sort((l0,l1) => l0.name.compareTo(l1.name) > 0); - def asString0(sigs : List[Signature]) : String = { - var ret = ""; - for (val sig <- sort(sigs)) - ret = ret + sig.asString; - ret; + def sort(sigs: List[Signature]) = + sigs.sort((l0,l1) => l0.name.compareTo(l1.name) > 0) + + def asString0(sigs: List[Signature]): String = { + var ret = "" + for (val sig <- sort(sigs)) ret = ret + sig.asString + ret } def signature(unit: CompilationUnit): String = asString0(signature(unit.body, Nil)) - def signature(trees : List[Tree]) : List[Signature] = { - var ret : List[Signature] = Nil; - for (val tree <- trees) ret = signature(tree, ret); - ret; + def signature(trees: List[Tree]): List[Signature] = { + var ret : List[Signature] = Nil + for (val tree <- trees) ret = signature(tree, ret) + ret } - def signature(tree0 : Tree, rest : List[Signature]) : List[Signature] = tree0 match { - case tree : MemberDef => if (!tree.mods.isPrivate) { - val name = "" + tree.name + "::" + tree.mods; - val children : List[Signature] = (tree match { - case impl : ImplDef => - val supers = new Signature("$$supers", signature(impl.impl.parents)); - val body = new Signature("$$body", signature(impl.impl.body)); - val ret = supers :: body :: Nil; - (impl match { - case cdef : ClassDef => new Signature("$$tparams", signature(cdef.tparams)) :: ret; - case _ => ret; - }); - case vdef : ValOrDefDef => - val ret = signature(vdef.tpt, Nil); - (vdef match { - case ddef : DefDef => - val tparams = new Signature("$$tparams", signature(ddef.tparams)); - var vparamss : List[Signature] = Nil; - for (val list <- ddef.vparamss) vparamss = signature(list) ::: vparamss; - new Signature("$$ret", ret) :: tparams :: vparamss; - case _ => ret; - }); - case pdef : PackageDef => signature(pdef.stats); - case _ => Nil; - }); - new Signature(name, children) :: rest; - } else rest; - case tree : TypeTree => new Signature("" + tree.tpe, Nil) :: rest; - case _ => rest; + /** + * @param tree0 ... + * @param rest ... + * @return ... + */ + def signature(tree0: Tree, rest: List[Signature]): List[Signature] = tree0 match { + case tree: MemberDef => if (!tree.mods.isPrivate) { + val name = "" + tree.name + "::" + tree.mods + val children: List[Signature] = tree match { + case impl: ImplDef => + val supers = new Signature("$$supers", signature(impl.impl.parents)) + val body = new Signature("$$body", signature(impl.impl.body)) + val ret = supers :: body :: Nil + impl match { + case cdef: ClassDef => + new Signature("$$tparams", signature(cdef.tparams)) :: ret + case _ => + ret + } + case vdef: ValOrDefDef => + val ret = signature(vdef.tpt, Nil) + vdef match { + case ddef : DefDef => + val tparams = new Signature("$$tparams", signature(ddef.tparams)) + var vparamss : List[Signature] = Nil + for (val list <- ddef.vparamss) + vparamss = signature(list) ::: vparamss + new Signature("$$ret", ret) :: tparams :: vparamss + case _ => + ret + } + case pdef: PackageDef => signature(pdef.stats) + case _ => Nil + } + new Signature(name, children) :: rest + + } else rest + case tree: TypeTree => new Signature("" + tree.tpe, Nil) :: rest + case _ => rest } } diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index cc47db0773..24092309cb 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -1,6 +1,6 @@ /* NSC -- new Scala compiler * Copyright 2005-2006 LAMP/EPFL - * @author + * @author Martin Odersky */ // $Id$ @@ -11,6 +11,11 @@ import Flags._ import scala.collection.mutable.{HashMap, ListBuffer} import matching.{TransMatcher, PatternNodes, CodeFactory, PatternMatchers} +/** This class ... + * + * @author Martin Odersky + * @version 1.0 + */ abstract class ExplicitOuter extends InfoTransform with TransMatcher with PatternNodes with CodeFactory with PatternMatchers with TypingTransformers { import global._ import definitions._ @@ -34,7 +39,8 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter private def outerField(clazz: Symbol): Symbol = { val result = clazz.info.member(nme.getterToLocal(nme.OUTER)) - if (result == NoSymbol) assert(false, "no outer field in "+clazz+clazz.info.decls+" at "+phase) + if (result == NoSymbol) + assert(false, "no outer field in "+clazz+clazz.info.decls+" at "+phase) result } @@ -42,7 +48,7 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter val firstTry = clazz.info.decl(clazz.expandedName(nme.OUTER)) if (firstTry != NoSymbol && firstTry.outerSource == clazz) firstTry else { - var e = clazz.info.decls.elems; + var e = clazz.info.decls.elems while (e != null && e.sym.outerSource != clazz) e = e.next if (e != null) e.sym else NoSymbol } @@ -65,9 +71,9 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter def transformInfo(sym: Symbol, tp: Type): Type = tp match { case MethodType(formals, restpe) => if (sym.owner.isTrait && ((sym hasFlag SUPERACCESSOR) || sym.isModule)) { // 5 - Console.println("make not private: "+sym+" "+sym.owner) + //Console.println("make not private: "+sym+" "+sym.owner)//debug sym.makeNotPrivate(sym.owner) - Console.println("made not private: "+sym) + //Console.println("made not private: "+sym)//debug } if (sym.owner.isTrait && (sym hasFlag PROTECTED)) sym setFlag notPROTECTED // 6 if (sym.isClassConstructor && isInner(sym.owner)) // 1 @@ -126,14 +132,18 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter /** Select and apply outer accessor from 'base' * The result is typed but not positioned. */ - private def outerSelect(base: Tree): Tree = { + private def outerSelect(base: Tree): Tree = localTyper.typed(Apply(Select(base, outerAccessor(base.tpe.symbol)), List())) - } /** 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 ... + * @param to ... + * @return ... */ protected def outerPath(base: Tree, from: Symbol, to: Symbol): Tree = { //Console.println("outerPath from "+from+" to "+to+" at "+base+":"+base.tpe) @@ -143,7 +153,7 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter } override def transform(tree: Tree): Tree = { - val savedOuterParam = outerParam; + val savedOuterParam = outerParam try { tree match { case Template(_, _) => @@ -220,7 +230,9 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter */ def mixinOuterAccessorDef(mixinClass: Symbol): Tree = { val outerAcc = outerAccessor(mixinClass).overridingSymbol(currentClass) - if (outerAcc == NoSymbol) Console.println("cc "+currentClass+":"+currentClass.info.decls+" at "+phase)//debug + if (outerAcc == NoSymbol) + Console.println("cc " + currentClass + ":" + currentClass.info.decls + + " at " + phase)//debug assert(outerAcc != NoSymbol) val path = gen.mkAttributedQualifier(currentClass.thisType.baseType(mixinClass).prefix) val rhs = ExplicitOuterTransformer.this.transform(path) @@ -308,10 +320,10 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter case Match(selector, cases) => // <----- transmatch hook val tid = unit.fresh.newName("tidmark") - if(settings.debug.value) + if (settings.debug.value) Console.println("transforming patmat with tidmark "+tid+" ncases = "+cases.length) - if((cases.length > 1)&&( treeInfo.isDefaultCase(cases(0)))) - assert(false,"transforming too much, "+tid) + if ((cases.length > 1) && (treeInfo.isDefaultCase(cases(0)))) + assert(false,"transforming too much, " + tid) val nselector = transform(selector) assert(nselector.tpe =:= selector.tpe) @@ -330,8 +342,8 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter //val t = atPos(tree.pos) { typed(t_untyped, resultType) } //val t = atPos(tree.pos) { typed(t_untyped) } //Console.println("t typed "+t.toString()) - if(settings.debug.value) - Console.println("finished translation of "+tid) + if (settings.debug.value) + Console.println("finished translation of " + tid) t case _ => diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 540ea6e687..5476f558b9 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -34,21 +34,25 @@ abstract class Mixin extends InfoTransform { * non-lifted private modules have been eliminated in ExplicitOuter) * - field accessors and superaccessors */ - private def isImplementedStatically(sym: Symbol) = ( + private def isImplementedStatically(sym: Symbol) = sym.owner.isImplClass && sym.isMethod && - (!sym.isModule || sym.hasFlag(PRIVATE)) && !(sym hasFlag (ACCESSOR | SUPERACCESSOR)) - ) + (!sym.isModule || sym.hasFlag(PRIVATE)) && + !(sym hasFlag (ACCESSOR | SUPERACCESSOR)) - /** A member of a trait is static only if it belongs only to the implementation - * class, not the interface, and it is implemented statically + /** A member of a trait is static only if it belongs only to the + * implementation class, not the interface, and it is implemented + * statically. */ - private def isStaticOnly(sym: Symbol) = isImplementedStatically(sym) && sym.isImplOnly + private def isStaticOnly(sym: Symbol) = + isImplementedStatically(sym) && sym.isImplOnly - /** A member of a trait is forwarded if it is implemented statically and it is also - * visible in the trait's interface. In that case, a forwarder to the member's - * static implementation will be added to the class that inherits the trait + /** A member of a trait is forwarded if it is implemented statically and it + * is also visible in the trait's interface. In that case, a forwarder to + * the member's static implementation will be added to the class that + * inherits the trait. */ - private def isForwarded(sym: Symbol) = isImplementedStatically(sym) && !sym.isImplOnly + private def isForwarded(sym: Symbol) = + isImplementedStatically(sym) && !sym.isImplOnly /** Maps the type of an implementation class to its interface; * maps all other types to themselves. @@ -56,8 +60,8 @@ abstract class Mixin extends InfoTransform { private def toInterface(tp: Type): Type = atPhase(currentRun.mixinPhase)(tp.symbol.toInterface).tpe - /** Maps all parts of this type that refer to implementation classes to their - * corresponding interfaces. + /** Maps all parts of this type that refer to implementation classes to + * their corresponding interfaces. */ private val toInterfaceMap = new TypeMap { def apply(tp: Type): Type = mapOver( tp match { @@ -67,12 +71,13 @@ abstract class Mixin extends InfoTransform { }) } - /** The implementation class corresponding to a currently compiled interface + /** The implementation class corresponding to a currently compiled interface. * todo: try to use Symbol.implClass instead? */ private def implClass(iface: Symbol): Symbol = erasure.implClass(iface) - /** Returns the symbol that is accessed by a super-accessor in a mixin composition + /** Returns the symbol that is accessed by a super-accessor in a mixin composition. + * * @param base The class in mwhich everything is mixed together * @param member The symbol statically referred to by the superaccessor in the trait * @param mixinClass The mixin class that produced the superaccessor @@ -87,7 +92,8 @@ abstract class Mixin extends InfoTransform { while (!bcs.isEmpty && sym == NoSymbol) { if (settings.debug.value) { val other = bcs.head.info.nonPrivateDecl(member.name); - log("rebindsuper " + bcs.head + " " + other + " " + other.tpe + " " + other.hasFlag(DEFERRED)) + log("rebindsuper " + bcs.head + " " + other + " " + other.tpe + + " " + other.hasFlag(DEFERRED)) } sym = member.overridingSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED | BRIDGE)) bcs = bcs.tail @@ -106,9 +112,12 @@ abstract class Mixin extends InfoTransform { member setFlag MIXEDIN } - /** Add getters and setters for all non-module fields of an implementation class - * to its interface unless they are already present. This is done only once per class. - * The mixedin flag is used to remember whether late members have been added to an interface. + /** Add getters and setters for all non-module fields of an implementation + * class to its interface unless they are already present. This is done + * only once per class. The mixedin flag is used to remember whether late + * members have been added to an interface. + * + * @param clazz ... */ def addLateInterfaceMembers(clazz: Symbol): unit = if (!(clazz hasFlag MIXEDIN)) { @@ -155,8 +164,8 @@ abstract class Mixin extends InfoTransform { * These are: * for every mixin trait T that is not also inherited by the superclass: * add late interface members to T and then: - * - if a member M of T is forwarded to the implementation class, add a forwarder for M - * unless one exists already. + * - if a member M of T is forwarded to the implementation class, add + * a forwarder for M unless one exists already. * The alias of the forwarder is the static member it forwards to. * - for every abstract accessor in T, add a field and an implementation for that acessor * - for every super accessor in T, add an implementation of that accessor @@ -210,7 +219,7 @@ abstract class Mixin extends InfoTransform { clazz, member.cloneSymbol(clazz) setPos clazz.pos - setFlag FINAL resetFlag (DEFERRED | lateDEFERRED)); + setFlag FINAL resetFlag (DEFERRED | lateDEFERRED)) if (!member.isSetter) member.tpe match { case MethodType(List(), ConstantType(_)) => @@ -246,7 +255,11 @@ abstract class Mixin extends InfoTransform { /** The info transform for this phase does the following: * - The parents of every class are mapped from implementation class to interface * - Implementation classes become modules that inherit nothing - * and that define all + * and that define all. + * + * @param sym ... + * @param tp ... + * @return ... */ override def transformInfo(sym: Symbol, tp: Type): Type = tp match { case ClassInfoType(parents, decls, clazz) => @@ -279,8 +292,10 @@ abstract class Mixin extends InfoTransform { case MethodType(formals, restp) => toInterfaceMap( - if (isImplementedStatically(sym)) MethodType(toInterface(sym.owner.typeOfThis) :: formals, restp) - else tp) + if (isImplementedStatically(sym)) + MethodType(toInterface(sym.owner.typeOfThis) :: formals, restp) + else + tp) case _ => tp @@ -293,19 +308,21 @@ abstract class Mixin extends InfoTransform { class MixinTransformer extends Transformer { - /** Within a static implementation method: the parameter referring to the current object - * undefined evrywhere else. + /** Within a static implementation method: the parameter referring to the + * current object undefined evrywhere else. */ private var self: Symbol = _ /** The rootContext used for typing */ - private val rootContext = erasure.NoContext.make(EmptyTree, RootClass, newScope) + private val rootContext = + erasure.NoContext.make(EmptyTree, RootClass, newScope) /** The typer */ private var localTyper: erasure.Typer = _ - /** Within a static implementation method: the interface type corresponding to the - * implementation module; undefined evrywhere else. */ + /** Within a static implementation method: the interface type corresponding + * to the implementation module; undefined evrywhere else. + */ private var enclInterface: Symbol = _ /** The first transform; called in a pre-order traversal at phase mixin @@ -315,7 +332,8 @@ abstract class Mixin extends InfoTransform { * - For every trait, add all late interface members to the class info * - For every static implementation method: * - remove override flag - * - create a new method definition that also has a `self' parameter (which comes first) + * - create a new method definition that also has a `self' parameter + * (which comes first) * - Map implementation class types in type-apply's to their interfaces * - Remove all fields in implementation classes */ @@ -326,7 +344,7 @@ abstract class Mixin extends InfoTransform { localTyper = erasure.newTyper(rootContext.make(tree, currentOwner)) atPhase(phase.next)(currentOwner.owner.info)//todo: needed? if (!currentOwner.isTrait) addMixedinMembers(currentOwner) - else if (currentOwner hasFlag lateINTERFACE) addLateInterfaceMembers(currentOwner); + else if (currentOwner hasFlag lateINTERFACE) addLateInterfaceMembers(currentOwner) tree case DefDef(mods, name, tparams, List(vparams), tpt, rhs) if currentOwner.isImplClass => if (isImplementedStatically(sym)) { @@ -334,8 +352,8 @@ abstract class Mixin extends InfoTransform { self = sym.newValue(sym.pos, nme.SELF) .setFlag(PARAM) .setInfo(toInterface(currentOwner.typeOfThis)); - enclInterface = currentOwner.toInterface; - val selfdef = ValDef(self) setType NoType; + enclInterface = currentOwner.toInterface + val selfdef = ValDef(self) setType NoType copy.DefDef(tree, mods, name, tparams, List(selfdef :: vparams), tpt, rhs) } else { EmptyTree @@ -355,12 +373,15 @@ abstract class Mixin extends InfoTransform { } } - /** Create an identifier which references self parameter + /** Create an identifier which references self parameter. + * + * @param pos ... */ - private def selfRef(pos: PositionType) = gen.mkAttributedIdent(self) setPos pos; + private def selfRef(pos: PositionType) = + gen.mkAttributedIdent(self) setPos pos - /** Create a static reference to given symbol `sym' of the form M.sym - * where M is the symbol's implementation module + /** Create a static reference to given symbol sym of the + * form M.sym where M is the symbol's implementation module. */ private def staticRef(sym: Symbol) = { sym.owner.info //todo: needed? @@ -392,7 +413,7 @@ abstract class Mixin extends InfoTransform { /** Attribute given tree and anchor at given position */ def attributedDef(pos: PositionType, tree: Tree): Tree = { - if (settings.debug.value) log("add new def to " + clazz + ": " + tree); + if (settings.debug.value) log("add new def to " + clazz + ": " + tree) localTyper.typed { atPos(pos) { tree } } } @@ -405,15 +426,18 @@ abstract class Mixin extends InfoTransform { def addDef(pos: PositionType, tree: Tree): unit = newDefs += attributedDef(pos, tree) - /** Add new method definition + /** Add new method definition. + * * @param sym The method - * @param rhs A function that maps formal parameters to the method's right-hand side + * @param rhs A function that maps formal parameters to the method's + * right-hand side */ def addDefDef(sym: Symbol, rhs: List[Symbol] => Tree): unit = addDef(position(sym), DefDef(sym, vparamss => rhs(vparamss.head))) - /** Add `newdefs' to `stats', removing any abstract method definitions in `stats' that - * are matched by some symbol defined in `newdefs'. + /** Add `newdefs' to `stats', removing any abstract method definitions + * in stats that are matched by some symbol defined in + * newDefs. */ def add(stats: List[Tree], newDefs: List[Tree]) = { val newSyms = newDefs map (.symbol) @@ -441,8 +465,8 @@ abstract class Mixin extends InfoTransform { if (stat.symbol hasFlag SUPERACCESSOR) => val rhs0 = Apply(Select(Super(clazz, nme.EMPTY.toTypeName), stat.symbol.alias), - vparams map (vparam => Ident(vparam.symbol))); - val rhs1 = localTyper.typed(atPos(stat.pos)(rhs0), stat.symbol.tpe.resultType); + vparams map (vparam => Ident(vparam.symbol))) + val rhs1 = localTyper.typed(atPos(stat.pos)(rhs0), stat.symbol.tpe.resultType) val rhs2 = atPhase(currentRun.mixinPhase)(transform(rhs1)) if (settings.debug.value) log("complete super acc " + stat.symbol + stat.symbol.locationString + @@ -469,12 +493,14 @@ abstract class Mixin extends InfoTransform { case MethodType(List(), ConstantType(c)) => Literal(c) case _ => Select(This(clazz), sym.accessed) } - if (sym.isSetter) Assign(accessedRef, Ident(vparams.head)) else accessedRef}) + if (sym.isSetter) Assign(accessedRef, Ident(vparams.head)) + else accessedRef + }) } else if (sym.isModule && !(sym hasFlag LIFTED | BRIDGE)) { // add modules - Console.println("add module "+sym+sym.hasFlag(EXPANDEDNAME)) + //Console.println("add module "+sym+sym.hasFlag(EXPANDEDNAME))//debug val vdef = gen.mkModuleVarDef(sym) - Console.println("add module "+sym+sym.hasFlag(EXPANDEDNAME)+":"+vdef.symbol.tpe) + //Console.println("add module "+sym+sym.hasFlag(EXPANDEDNAME)+":"+vdef.symbol.tpe)//debug addDef(position(sym), vdef) addDef(position(sym), gen.mkModuleAccessDef(sym, vdef.symbol)) } else if (!sym.isMethod) { @@ -497,8 +523,8 @@ abstract class Mixin extends InfoTransform { stats1 } - /** The transform that gets applied to a tree after it has been completely traversed - * and possible modified by a preTransform. + /** The transform that gets applied to a tree after it has been completely + * traversed and possible modified by a preTransform. * This step will * - change every node type that refers to an implementation class to its * corresponding interface, unless the node's symbol is an implementation class. @@ -507,7 +533,8 @@ abstract class Mixin extends InfoTransform { * - remove widening casts * - change calls to methods which are defined only in implementation classes * to static calls of methods in implementation modules (@see staticCall) - * - change super calls to methods in implementation classes to static calls (@see staticCall) + * - change super calls to methods in implementation classes to static calls + * (@see staticCall) * - change `this' in implementation modules to references to the self parameter * - refer to fields in some implementation class vie an abstract method in the interface. */ @@ -536,11 +563,13 @@ abstract class Mixin extends InfoTransform { qual case Apply(Select(qual, _), args) => - /** Changes `qual.m(args)' where m refers to an implementation class method to - * Q.m(S, args) where Q is the implementation module of `m' and - * S is the self parameter for the call, which is determined as follows: + /** Changes qual.m(args) where m refers to an implementation + * class method to Q.m(S, args) where Q is the implementation module of + * m and S is the self parameter for the call, which + * is determined as follows: * - if qual != super, qual itself - * - if qual == super, and we are in an implementation class, the current self parameter. + * - if qual == super, and we are in an implementation class, + * the current self parameter. * - if qual == super, and we are not in an implementation class, `this' */ def staticCall(target: Symbol) = { @@ -557,8 +586,8 @@ abstract class Mixin extends InfoTransform { } } if (isStaticOnly(sym)) { - // change calls to methods which are defined only in implementation classes - // to static calls of methods in implementation modules + // change calls to methods which are defined only in implementation + // classes to static calls of methods in implementation modules staticCall(sym) } else qual match { case Super(_, mix) => @@ -588,8 +617,11 @@ abstract class Mixin extends InfoTransform { tree case Select(qual, name) if sym.owner.isImplClass && !isStaticOnly(sym) => - // refer to fields in some implementation class via an abstract getter in the interface. - if (sym.isMethod) assert(false, "no method allowed here: "+sym+sym.isImplOnly+" "+flagsToString(sym.flags)) + // refer to fields in some implementation class via an abstract + // getter in the interface. + if (sym.isMethod) + assert(false, "no method allowed here: " + sym + sym.isImplOnly + + " " + flagsToString(sym.flags)) val getter = sym.getter(enclInterface) assert(getter != NoSymbol) localTyper.typed { @@ -599,7 +631,8 @@ abstract class Mixin extends InfoTransform { } case Assign(Apply(lhs @ Select(qual, _), List()), rhs) => - // assign to fields in some implementation class via an abstract setter in the interface. + // assign to fields in some implementation class via an abstract + // setter in the interface. localTyper.typed { atPos(tree.pos) { Apply(Select(qual, lhs.symbol.setter(enclInterface)) setPos lhs.pos, List(rhs)) -- cgit v1.2.3