summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-09-14 14:28:15 +0000
committermichelou <michelou@epfl.ch>2006-09-14 14:28:15 +0000
commit01d4e3645aa72e36b14c97f7ae100ca016deefcb (patch)
tree1d67f6eb94e029a2cd48d455358934e76ec40d69 /src
parent0f3a8b5a8e4af920a51ac380c91283338005137a (diff)
downloadscala-01d4e3645aa72e36b14c97f7ae100ca016deefcb.tar.gz
scala-01d4e3645aa72e36b14c97f7ae100ca016deefcb.tar.bz2
scala-01d4e3645aa72e36b14c97f7ae100ca016deefcb.zip
removed leading/trailing tabs/blanks in typeche...
removed leading/trailing tabs/blanks in typechecker/*.scala
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala64
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala102
2 files changed, 94 insertions, 72 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
index de70ccf5a7..154ec66c09 100644
--- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
@@ -1,17 +1,23 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
+/* NSC -- new Scala compiler
+ * Copyright 2005-2006 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.typechecker;
-import scala.collection.mutable.ListBuffer;
-import symtab.Flags._;
+package scala.tools.nsc.typechecker
+import scala.collection.mutable.ListBuffer
+import symtab.Flags._
+
+/** This trait ...
+ *
+ * @author Martin Odersky
+ * @version 1.0
+ */
trait EtaExpansion requires Analyzer {
- import global._;
- import posAssigner.atPos;
+ import global._
+ import posAssigner.atPos
/** Expand partial function applications of type `type'.
*
@@ -27,47 +33,57 @@ trait EtaExpansion requires Analyzer {
* tree is already attributed
*/
def etaExpand(tree: Tree): Tree = {
- val tpe = tree.tpe;
- var cnt = 0;
+ val tpe = tree.tpe
+ var cnt = 0
def freshName() = { cnt = cnt + 1; newTermName("eta$" + cnt) }
- val defs = new ListBuffer[Tree];
+ val defs = new ListBuffer[Tree]
/** Append to `defs' value definitions for all non-stable subexpressions
- * of the function application `tree' */
+ * of the function application <code>tree</code>
+ *
+ * @param tree ...
+ * @return ...
+ */
def liftoutPrefix(tree: Tree): Tree = {
def liftout(tree: Tree): Tree =
- if (treeInfo.isPureExpr(tree)) tree
- else {
- val vname: Name = freshName();
- defs += atPos(tree.pos)(ValDef(Modifiers(SYNTHETIC), vname, TypeTree(), tree));
- Ident(vname) setPos tree.pos
- }
+ if (treeInfo.isPureExpr(tree)) tree
+ else {
+ val vname: Name = freshName()
+ defs += atPos(tree.pos)(ValDef(Modifiers(SYNTHETIC), vname, TypeTree(), tree))
+ Ident(vname) setPos tree.pos
+ }
tree match {
- case Apply(fn, args) =>
+ case Apply(fn, args) =>
copy.Apply(tree, liftoutPrefix(fn), List.mapConserve(args)(liftout)) setType null
- case TypeApply(fn, args) =>
+ case TypeApply(fn, args) =>
copy.TypeApply(tree, liftoutPrefix(fn), args) setType null
- case Select(qual, name) =>
+ case Select(qual, name) =>
copy.Select(tree, liftout(qual), name) setSymbol NoSymbol setType null
case Ident(name) =>
tree
}
}
- /** Eta-expand lifted tree */
+ /** Eta-expand lifted tree.
+ *
+ * @param tree ...
+ * @param tpe ...
+ * @return ...
+ */
def expand(tree: Tree, tpe: Type): Tree = tpe match {
case mt: ImplicitMethodType =>
tree
case MethodType(formals, restpe) =>
val params = formals map (formal =>
- ValDef(Modifiers(SYNTHETIC | PARAM), freshName(), TypeTree().setType(formal), EmptyTree));
- val args = params map (param => Ident(param.name));
+ ValDef(Modifiers(SYNTHETIC | PARAM), freshName(), TypeTree()
+ .setType(formal), EmptyTree))
+ val args = params map (param => Ident(param.name))
atPos(tree.pos)(Function(params, expand(Apply(tree, args), restpe)))
case _ =>
tree
}
- val tree1 = liftoutPrefix(tree);
+ val tree1 = liftoutPrefix(tree)
atPos(tree.pos)(Block(defs.toList, expand(tree1, tpe)))
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index f0eafea67e..42c03ab884 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -1,12 +1,13 @@
-/* NSC -- new scala compiler
- * Copyright 2005 LAMP/EPFL
- * @author
+/* NSC -- new Scala compiler
+ * Copyright 2005-2006 LAMP/EPFL
+ * @author Martin Odersky
*/
// $Id$
-package scala.tools.nsc.typechecker;
-import scala.collection.mutable.ListBuffer;
-import nsc.symtab.Flags._;
+package scala.tools.nsc.typechecker
+
+import scala.collection.mutable.ListBuffer
+import nsc.symtab.Flags._
/** This phase adds super accessors for all super calls that
* either appear in a trait or have as a target a member of some outer class.
@@ -16,24 +17,29 @@ import nsc.symtab.Flags._;
* or are overridden by an abstract override.
* Finally, the phase also mangles the names of class-members which are private
* up to an enclosing non-package class, in order to avoid overriding conflicts.
+ *
+ * @author Martin Odersky
+ * @version 1.0
*/
abstract class SuperAccessors extends transform.Transform {
// inherits abstract value `global' and class `Phase' from Transform
- import global._;
- import posAssigner.atPos;
- import typer.typed;
+ import global._
+ import posAssigner.atPos
+ import typer.typed
/** the following two members override abstract members in Transform */
- val phaseName: String = "superaccessors";
+ val phaseName: String = "superaccessors"
- protected def newTransformer(unit: CompilationUnit): Transformer = new SuperAccTransformer(unit);
+ protected def newTransformer(unit: CompilationUnit): Transformer =
+ new SuperAccTransformer(unit)
class SuperAccTransformer(unit: CompilationUnit) extends Transformer {
- private var validCurrentOwner = true;
- private var accDefs: List[Pair[Symbol, ListBuffer[Tree]]] = List();
+ private var validCurrentOwner = true
+ private var accDefs: List[Pair[Symbol, ListBuffer[Tree]]] = List()
- private def accDefBuf(clazz: Symbol) = accDefs.dropWhile(._1.!=(clazz)).head._2;
+ private def accDefBuf(clazz: Symbol) =
+ accDefs.dropWhile(._1.!=(clazz)).head._2
private def transformArgs(args: List[Tree], formals: List[Type]) = {
if (!formals.isEmpty && formals.last.symbol == definitions.ByNameParamClass)
@@ -56,51 +62,51 @@ abstract class SuperAccessors extends transform.Transform {
}
super.transform(tree)
case Template(parents, body) =>
- val ownAccDefs = new ListBuffer[Tree];
- accDefs = Pair(currentOwner, ownAccDefs) :: accDefs;
- val body1 = transformTrees(body);
- accDefs = accDefs.tail;
- copy.Template(tree, parents, ownAccDefs.toList ::: body1);
+ val ownAccDefs = new ListBuffer[Tree]
+ accDefs = Pair(currentOwner, ownAccDefs) :: accDefs;
+ val body1 = transformTrees(body)
+ accDefs = accDefs.tail
+ copy.Template(tree, parents, ownAccDefs.toList ::: body1)
case Select(qual @ This(_), name) =>
- val sym = tree.symbol;
- if ((sym hasFlag PARAMACCESSOR) && (sym.alias != NoSymbol)) {
+ val sym = tree.symbol
+ if ((sym hasFlag PARAMACCESSOR) && (sym.alias != NoSymbol)) {
val result = typed {
Select(
Super(qual.symbol, nme.EMPTY.toTypeName/*qual.symbol.info.parents.head.symbol.name*/) setPos qual.pos,
sym.alias) setPos tree.pos
}
- if (settings.debug.value)
- System.out.println("alias replacement: " + tree + " ==> " + result);//debug
+ if (settings.debug.value)
+ System.out.println("alias replacement: " + tree + " ==> " + result);//debug
transform(result)
} else tree
case Select(sup @ Super(_, mix), name) =>
- val sym = tree.symbol;
- val clazz = sup.symbol;
+ val sym = tree.symbol
+ val clazz = sup.symbol
if (sym hasFlag DEFERRED) {
- val member = sym.overridingSymbol(clazz);
- if (mix != nme.EMPTY.toTypeName || member == NoSymbol ||
- !((member hasFlag ABSOVERRIDE) && member.isIncompleteIn(clazz)))
- unit.error(tree.pos, ""+sym+sym.locationString+" is accessed from super. It may not be abstract "+
+ val member = sym.overridingSymbol(clazz);
+ if (mix != nme.EMPTY.toTypeName || member == NoSymbol ||
+ !((member hasFlag ABSOVERRIDE) && member.isIncompleteIn(clazz)))
+ unit.error(tree.pos, ""+sym+sym.locationString+" is accessed from super. It may not be abstract "+
"unless it is overridden by a member declared `abstract' and `override'");
}
- if (tree.isTerm && mix == nme.EMPTY.toTypeName &&
- (clazz.isTrait || clazz != currentOwner.enclClass || !validCurrentOwner)) {
- val supername = nme.superName(sym.name);
- var superAcc = clazz.info.decl(supername).suchThat(.alias.==(sym));
- if (superAcc == NoSymbol) {
- if (settings.debug.value) log("add super acc " + sym + sym.locationString + " to `" + clazz);//debug
+ if (tree.isTerm && mix == nme.EMPTY.toTypeName &&
+ (clazz.isTrait || clazz != currentOwner.enclClass || !validCurrentOwner)) {
+ val supername = nme.superName(sym.name)
+ var superAcc = clazz.info.decl(supername).suchThat(.alias.==(sym))
+ if (superAcc == NoSymbol) {
+ if (settings.debug.value) log("add super acc " + sym + sym.locationString + " to `" + clazz);//debug
superAcc =
clazz.newMethod(tree.pos, supername)
- .setFlag(SUPERACCESSOR | PRIVATE)
- .setInfo(clazz.thisType.memberType(sym))
- .setAlias(sym)
+ .setFlag(SUPERACCESSOR | PRIVATE)
+ .setInfo(clazz.thisType.memberType(sym))
+ .setAlias(sym)
clazz.info.decls enter superAcc;
- accDefBuf(clazz) += typed(DefDef(superAcc, vparamss => EmptyTree))
- }
- atPos(sup.pos) {
- Select(gen.mkAttributedThis(clazz), superAcc) setType tree.tpe;
- }
- } else tree
+ accDefBuf(clazz) += typed(DefDef(superAcc, vparamss => EmptyTree))
+ }
+ atPos(sup.pos) {
+ Select(gen.mkAttributedThis(clazz), superAcc) setType tree.tpe;
+ }
+ } else tree
case Apply(fn, args) =>
copy.Apply(tree, transform(fn), transformArgs(args, fn.tpe.paramTypes))
case Function(vparams, body) =>
@@ -117,10 +123,10 @@ abstract class SuperAccessors extends transform.Transform {
}
private def withInvalidOwner[A](trans: => A): A = {
- val prevValidCurrentOwner = validCurrentOwner;
- validCurrentOwner = false;
- val result = trans;
- validCurrentOwner = prevValidCurrentOwner;
+ val prevValidCurrentOwner = validCurrentOwner
+ validCurrentOwner = false
+ val result = trans
+ validCurrentOwner = prevValidCurrentOwner
result
}
}