summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-08-17 08:34:10 -0700
committerPaul Phillips <paulp@improving.org>2013-08-17 10:58:13 -0700
commitc5f7aaca72591ebb8e892e8781aa51b144201e36 (patch)
tree730f56c2d7151ea752d89889cfe354c04b407ebf /src/compiler
parent13ad734393dc088a3ea30fd57da339247f779cb8 (diff)
downloadscala-c5f7aaca72591ebb8e892e8781aa51b144201e36.tar.gz
scala-c5f7aaca72591ebb8e892e8781aa51b144201e36.tar.bz2
scala-c5f7aaca72591ebb8e892e8781aa51b144201e36.zip
Turned TreeMaker into case class.
Type aliases are better than naked tuples, but only barely.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
index 682631b70d..ae406ad8dd 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTranslation.scala
@@ -52,6 +52,11 @@ trait MatchTranslation extends CpsPatternHacks {
trait MatchTranslator extends TreeMakers {
import typer.context
+ // a list of TreeMakers that encode `patTree`, and a list of arguments for recursive invocations of `translatePattern` to encode its subpatterns
+ private case class TranslationStep(makers: List[TreeMaker], subpatterns: List[(Symbol, Tree)]) {
+ def merge(f: (Symbol, Tree) => List[TreeMaker]): List[TreeMaker] = makers ::: (subpatterns flatMap f.tupled)
+ }
+
// Why is it so difficult to say "here's a name and a context, give me any
// matching symbol in scope" ? I am sure this code is wrong, but attempts to
// use the scopes of the contexts in the enclosing context chain discover
@@ -234,15 +239,14 @@ trait MatchTranslation extends CpsPatternHacks {
* a function that will take care of binding and substitution of the next ast (to the right).
*
*/
- def translateCase(scrutSym: Symbol, pt: Type)(caseDef: CaseDef) = caseDef match { case CaseDef(pattern, guard, body) =>
+ def translateCase(scrutSym: Symbol, pt: Type)(caseDef: CaseDef) = {
+ val CaseDef(pattern, guard, body) = caseDef
translatePattern(scrutSym, pattern) ++ translateGuard(guard) :+ translateBody(body, pt)
}
def translatePattern(patBinder: Symbol, patTree: Tree): List[TreeMaker] = {
- // a list of TreeMakers that encode `patTree`, and a list of arguments for recursive invocations of `translatePattern` to encode its subpatterns
- type TranslationStep = (List[TreeMaker], List[(Symbol, Tree)])
- def withSubPats(treeMakers: List[TreeMaker], subpats: (Symbol, Tree)*): TranslationStep = (treeMakers, subpats.toList)
- def noFurtherSubPats(treeMakers: TreeMaker*): TranslationStep = (treeMakers.toList, Nil)
+ def withSubPats(treeMakers: List[TreeMaker], subpats: (Symbol, Tree)*): TranslationStep = TranslationStep(treeMakers, subpats.toList)
+ def noFurtherSubPats(treeMakers: TreeMaker*): TranslationStep = TranslationStep(treeMakers.toList, Nil)
val pos = patTree.pos
@@ -339,7 +343,7 @@ trait MatchTranslation extends CpsPatternHacks {
// [6] pattern alternatives
// [7] symbol-less bind patterns - this happens in certain ill-formed programs, there'll be an error later
// don't fail here though (or should we?)
- val (treeMakers, subpats) = patTree match {
+ val translationStep = patTree match {
case WildcardPattern() => none()
case UnApply(unfun, args) => translateExtractorPattern(ExtractorCall(unfun, args))
case Apply(fun, args) => ExtractorCall.fromCaseClass(fun, args) map translateExtractorPattern getOrElse noFurtherSubPats()
@@ -351,9 +355,7 @@ trait MatchTranslation extends CpsPatternHacks {
case _ => context.unit.error(patTree.pos, unsupportedPatternMsg) ; none()
}
- treeMakers ++ subpats.flatMap { case (binder, pat) =>
- translatePattern(binder, pat) // recurse on subpatterns
- }
+ translationStep merge translatePattern
}
def translateGuard(guard: Tree): List[TreeMaker] =