From 79997446834008008c30d9b0c3292516f84b04d6 Mon Sep 17 00:00:00 2001 From: David MacIver Date: Tue, 4 Nov 2008 00:42:23 +0000 Subject: General code cleanliness. Nothing too exciting. --- .../scala/tools/nsc/matching/CodeFactory.scala | 3 +- .../tools/nsc/matching/ParallelMatching.scala | 15 +++++----- .../scala/tools/nsc/matching/PatternNodes.scala | 33 ++++------------------ .../scala/tools/nsc/transform/ExplicitOuter.scala | 16 +---------- 4 files changed, 16 insertions(+), 51 deletions(-) diff --git a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala index 6918bf0674..d072590d70 100644 --- a/src/compiler/scala/tools/nsc/matching/CodeFactory.scala +++ b/src/compiler/scala/tools/nsc/matching/CodeFactory.scala @@ -88,7 +88,8 @@ trait CodeFactory { case Literal(Constant(false)) => Literal(Constant(true)) case t => Select(arg, definitions.Boolean_not) } - /*protected*/ def And(left: Tree, right: Tree): Tree = left match { + + def And(left: Tree, right: Tree): Tree = left match { case Literal(Constant(value: Boolean)) => if (value) right else left case _ => diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 156f1c134d..fec4c10d8f 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -8,6 +8,7 @@ package scala.tools.nsc.matching import util.Position +import collection._ import collection.mutable.BitSet import collection.immutable.IntMap import MatchUtil.ListPlus._ @@ -192,7 +193,7 @@ trait ParallelMatching { if (isDefaultPattern(p)) insertDefault(i, strip1(x)) else - insertTagIndexPair(getCaseTag(p.tpe), i) + insertTagIndexPair(p.tpe.typeSymbol.tag, i) override def grabTemps = scrutinee::rest.temp @@ -297,8 +298,6 @@ trait ParallelMatching { v } - private def bindToScrutinee(x: Symbol) = typedValDef(x, mkIdent(scrutinee)) // XXX this is dead code - /** returns (unapply-call, success-rep, optional fail-rep*/ final def getTransition(implicit theOwner: Symbol): (Tree, List[Tree], Rep, Option[Rep]) = { object sameUnapplyCall { @@ -677,13 +676,13 @@ trait ParallelMatching { def _2 = row } - var vss: List[SymList] = _ + var vss: List[List[Symbol]] = _ var labels: Array[Symbol] = new Array[Symbol](4) var targets: List[Tree] = _ var reached: BitSet = _ var shortCuts: List[Symbol] = Nil - final def make(temp:List[Symbol], row:List[Row], targets: List[Tree], vss:List[SymList])(implicit theOwner: Symbol): Rep = { + final def make(temp:List[Symbol], row:List[Row], targets: List[Tree], vss:List[List[Symbol]])(implicit theOwner: Symbol): Rep = { // ensured that labels(i) eq null for all i, cleanup() has to be called after translation this.targets = targets if (targets.length > labels.length) @@ -909,7 +908,7 @@ trait ParallelMatching { val row: List[Row] final def init: this.type = { - val setsToCombine: List[(Int, SymSet)] = + val setsToCombine: List[(Int, immutable.Set[Symbol])] = for { (sym, i) <- temp.zipWithIndex if sym hasFlag Flags.MUTABLE // indicates that have not yet checked exhaustivity @@ -918,7 +917,7 @@ trait ParallelMatching { } yield { sym resetFlag Flags.MUTABLE // this should enumerate all cases... however, also the superclass is taken if it is not abstract - def candidates(tpesym: Symbol): SymSet = { + def candidates(tpesym: Symbol): immutable.Set[Symbol] = { def countCandidates(x: Symbol) = if (x hasFlag Flags.ABSTRACT) candidates(x) else candidates(x) + x if (tpesym hasFlag Flags.SEALED) tpesym.children.flatMap(countCandidates) else emptySymbolSet @@ -1025,7 +1024,7 @@ trait ParallelMatching { */ final def initRep(roots: List[Symbol], cases: List[Tree], rep: RepFactory)(implicit theOwner: Symbol) = { // communicate whether exhaustiveness-checking is enabled via some flag - val (rows, targets, vss): (List[Option[Row]], List[Tree], List[SymList]) = unzip3( + val (rows, targets, vss): (List[Option[Row]], List[Tree], List[List[Symbol]]) = unzip3( for ((CaseDef(pat, g, b), bx) <- cases.zipWithIndex) yield { // stash away pvars and bodies for later def rowForPat: Option[Row] = pat match { case _ if roots.length <= 1 => Some(Row(List(pat), NoBinding, g, bx)) diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala index 6ab57f4b5b..ab59c4427b 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala @@ -18,7 +18,7 @@ trait PatternNodes { self: transform.ExplicitOuter => final def getDummies(i: Int): List[Tree] = List.make(i, EmptyTree) - def makeBind(vs:SymList, pat:Tree): Tree = + def makeBind(vs:List[Symbol], pat:Tree): Tree = if (vs eq Nil) pat else Bind(vs.head, makeBind(vs.tail, pat)) setType pat.tpe def normalizedListPattern(pats:List[Tree], tptArg:Type): Tree = pats match { @@ -87,35 +87,18 @@ trait PatternNodes { self: transform.ExplicitOuter => case z => (emptySymbolSet, z) } - final def strip1(x: Tree): Set[Symbol] = x match { // same as strip(x)._1 - case b @ Bind(_,pat) => strip1(pat) + b.symbol - case z => emptySymbolSet - } - final def strip2(x: Tree): Tree = x match { // same as strip(x)._2 - case Bind(_,pat) => strip2(pat) - case z => z - } - object StrippedPat { - def unapply(x: Tree): Option[Tree] = Some(strip2(x)) - } + final def strip1(x: Tree): Set[Symbol] = strip(x)._1 + final def strip2(x: Tree): Tree = strip(x)._2; - final def isCaseClass(tpe: Type): Boolean = tpe match { - case TypeRef(_, sym, _) => - if (sym.isAliasType) tpe.normalize.typeSymbol hasFlag Flags.CASE - else sym hasFlag Flags.CASE - case _ => false - } + final def isCaseClass(tpe: Type): Boolean = + tpe.typeSymbol hasFlag Flags.CASE final def isEqualsPattern(tpe: Type): Boolean = tpe match { case TypeRef(_, sym, _) => sym eq definitions.EqualsPatternClass case _ => false } - - // this method obtains tag method in a defensive way - final def getCaseTag(x:Type): Int = { x.typeSymbol.tag } - - final def definedVars(x: Tree): SymList = { + final def definedVars(x: Tree): List[Symbol] = { implicit def listToStream[T](xs: List[T]): Stream[T] = xs.toStream def definedVars1(x: Tree): Stream[Symbol] = x match { case Apply(_, args) => definedVars2(args) @@ -155,8 +138,4 @@ trait PatternNodes { self: transform.ExplicitOuter => override def toString = "." override def equals(x:Any) = x.isInstanceOf[Binding] && (x.asInstanceOf[Binding] eq this) } - - type SymSet = collection.immutable.Set[Symbol] - type SymList = List[Symbol] - } diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index 5c7480d0f4..3d5431fcb2 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -415,24 +415,10 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter q } else null - /* - cases match { - //if ((cases.length > 1) && ...(cases(0))) - //can't use treeInfo.isDefaultCase, because that diagnoses a Bind - case CaseDef(Ident(nme.WILDCARD), EmptyTree, _)::xs if !xs.isEmpty => - // a hack to detect when explicit outer does not work correctly - // still needed? - assert(false,"transforming too much, " + tid) - // no! - case _ => - } - */ var nselector = transform(selector) - //assert(nselector.tpe =:= selector.tpe) - //val ncases = transformCaseDefs(cases) - def makeGuardDef(vs:SymList, guard:Tree) = { + def makeGuardDef(vs:List[Symbol], guard:Tree) = { import symtab.Flags._ val gdname = cunit.fresh.newName(guard.pos, "gd") val fmls = new ListBuffer[Type] -- cgit v1.2.3