summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-30 14:37:15 +0000
committerPaul Phillips <paulp@improving.org>2009-06-30 14:37:15 +0000
commitd14b4a117e477505afa4b2417133d3b8325ba4d3 (patch)
tree2baa570a81a734435186dd34e187db002255af44 /src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
parent19c3aa9b31d9253b73469b3aad50112bd4084a68 (diff)
downloadscala-d14b4a117e477505afa4b2417133d3b8325ba4d3.tar.gz
scala-d14b4a117e477505afa4b2417133d3b8325ba4d3.tar.bz2
scala-d14b4a117e477505afa4b2417133d3b8325ba4d3.zip
More elucidation work on the pattern matcher.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala69
1 files changed, 29 insertions, 40 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index e4c4ea9fd9..40eeb572cd 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -164,7 +164,6 @@ abstract class ExplicitOuter extends InfoTransform
* The class provides methods for referencing via outer.
*/
abstract class OuterPathTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
-
/** The directly enclosing outer parameter, if we are in a constructor */
protected var outerParam: Symbol = NoSymbol
@@ -296,22 +295,17 @@ abstract class ExplicitOuter extends InfoTransform
/** The definition tree of the outer accessor of current class
*/
- def outerFieldDef: Tree = {
- val outerFld = outerField(currentClass)
- ValDef(outerFld, EmptyTree)
- }
+ def outerFieldDef: Tree = VAL(outerField(currentClass)) === EmptyTree
/** The definition tree of the outer accessor of current class
*/
def outerAccessorDef: Tree = {
val outerAcc = outerAccessor(currentClass)
- var rhs = if (outerAcc.isDeferred) EmptyTree
- else Select(This(currentClass), outerField(currentClass))
- localTyper.typed {
- atPos(currentClass.pos) {
- DefDef(outerAcc, rhs)
- }
- }
+ var rhs: Tree =
+ if (outerAcc.isDeferred) EmptyTree
+ else This(currentClass) DOT outerField(currentClass)
+
+ typedPos(currentClass.pos)(DEF(outerAcc) === rhs)
}
/** The definition tree of the outer accessor for class
@@ -328,23 +322,28 @@ abstract class ExplicitOuter extends InfoTransform
if (mixinClass.owner.isTerm) gen.mkAttributedThis(mixinClass.owner.enclClass)
else gen.mkAttributedQualifier(currentClass.thisType.baseType(mixinClass).prefix)
val rhs = ExplicitOuterTransformer.this.transform(path)
- rhs.setPos(currentClass.pos) // see note below
- localTyper.typed {
- atPos(currentClass.pos) {
- // @S: atPos not good enough because of nested atPos in DefDef method, which gives position from wrong class!
- DefDef(outerAcc, rhs).setPos(currentClass.pos)
- }
- }
+
+ // @S: atPos not good enough because of nested atPos in DefDef method, which gives position from wrong class!
+ rhs setPos currentClass.pos
+ typedPos(currentClass.pos) { (DEF(outerAcc) === rhs) setPos currentClass.pos }
+ }
+
+ /** If FLAG is set on symbol, sets notFLAG (this exists in anticipation of generalizing). */
+ def setNotFlags(sym: Symbol, flags: Int*) {
+ val notMap = Map(
+ PRIVATE -> notPRIVATE,
+ PROTECTED -> notPROTECTED
+ )
+ for (f <- flags ; notFlag <- notMap get f ; if sym hasFlag f)
+ sym setFlag notFlag
}
/** The main transformation method */
override def transform(tree: Tree): Tree = {
-
val sym = tree.symbol
- if ((sym ne null) && sym.isType) {//(9)
- if (sym hasFlag PRIVATE) sym setFlag notPRIVATE
- if (sym hasFlag PROTECTED) sym setFlag notPROTECTED
- }
+ if (sym != null && sym.isType) //(9)
+ setNotFlags(sym, PRIVATE, PROTECTED)
+
tree match {
case Template(parents, self, decls) =>
val newDefs = new ListBuffer[Tree]
@@ -414,27 +413,17 @@ abstract class ExplicitOuter extends InfoTransform
var nselector = transform(selector)
def makeGuardDef(vs: List[Symbol], guard: Tree) = {
- import symtab.Flags._
val gdname = cunit.fresh.newName(guard.pos, "gd")
val method = currentOwner.newMethod(mch.pos, gdname) setFlag SYNTHETIC
val fmls = vs map (_.tpe)
val tpe = new MethodType(method newSyntheticValueParams fmls, BooleanClass.tpe)
method setInfo tpe
- // XXX integrate
- // localTyper typed (DEF(method) === {
- // new ChangeOwnerTraverser(currentOwner, method) traverse guard
- // new TreeSymSubstituter(vs, method.paramss.head) traverse guard
- // guard
- // })
- //
- localTyper.typed(
- DefDef(method, {
- new ChangeOwnerTraverser(currentOwner, method) traverse guard
- new TreeSymSubstituter(vs, method.paramss.head) traverse guard
- guard
- })
- )
+ localTyper typed (DEF(method) === {
+ new ChangeOwnerTraverser(currentOwner, method) traverse guard
+ new TreeSymSubstituter(vs, method.paramss.head) traverse guard
+ guard
+ })
}
val nguard = new ListBuffer[Tree]
@@ -447,7 +436,7 @@ abstract class ExplicitOuter extends InfoTransform
val guardDef = makeGuardDef(vs, guard)
nguard += transform(guardDef) // building up list of guards
- localTyper typed (Ident(guardDef.symbol) APPLY(vs map Ident))
+ localTyper typed (Ident(guardDef.symbol) APPLY (vs map Ident))
}
(CASE(transform(p)) IF gdcall) ==> transform(b)