diff options
author | michelou <michelou@epfl.ch> | 2007-04-23 15:38:07 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-04-23 15:38:07 +0000 |
commit | bd7866c7940c41d5c4f3f88e09c7354126eabe15 (patch) | |
tree | 7b2a2bd12160cf920fac5fd7867218ded4f0967c /src/compiler | |
parent | 90c68e19144fa811671b8e1dc3ad0e7ecc5b487c (diff) | |
download | scala-bd7866c7940c41d5c4f3f88e09c7354126eabe15.tar.gz scala-bd7866c7940c41d5c4f3f88e09c7354126eabe15.tar.bz2 scala-bd7866c7940c41d5c4f3f88e09c7354126eabe15.zip |
updated self aliases, for-comprehensions
Diffstat (limited to 'src/compiler')
10 files changed, 142 insertions, 137 deletions
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala b/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala index 4ba176d0fe..3e9c3e706b 100644 --- a/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala +++ b/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala @@ -1,5 +1,5 @@ /* NSC -- new Scala compiler - * Copyright 2006 LAMP/EPFL + * Copyright 2006-2007 LAMP/EPFL * @author Lex Spoon */ @@ -29,13 +29,11 @@ extends Settings(error) { "-nocompdaemon", "do not use the fsc compilation daemon") - /* For some reason, "object defines extends Setting(...)" - does not work here. The object is present but the setting - is not added to allsettings. Thus, - */ - class DefinesSetting - extends Setting("set a Java property") - { + /** For some reason, "object defines extends Setting(...)" + * does not work here. The object is present but the setting + * is not added to allsettings. Thus, + */ + class DefinesSetting extends Setting("set a Java property") { def name = "-D<prop>" @@ -47,17 +45,15 @@ extends Settings(error) { args match { case arg0::rest if arg0.startsWith("-D") => - { val stripD = arg0.substring(2) val eqidx = stripD.indexOf('=') val addition = - if(eqidx < 0) + if (eqidx < 0) (stripD, "") else (stripD.substring(0, eqidx), stripD.substring(eqidx+1)) props += addition rest - } case _ => args } @@ -66,7 +62,7 @@ extends Settings(error) { /** Apply the specified properties to the current JVM */ def applyToCurrentJVM = { val systemProps = getProperties - for(val (key, value) <- props.toList) + for ((key, value) <- props.toList) systemProps.setProperty(key, value) } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index e9f388f1f3..bdbc3532b4 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1877,7 +1877,7 @@ trait Parsers { } trees } - for (val p <- lhs.toList; val d <- mkDefs(p)) yield d + for (p <- lhs.toList; d <- mkDefs(p)) yield d } /** VarDef ::= Id {`,' Id} [`:' Type] `=' Expr @@ -1903,7 +1903,7 @@ trait Parsers { newmods = newmods | Flags.DEFERRED EmptyTree } - for (val (pos, name) <- lhs.toList) yield + for ((pos, name) <- lhs.toList) yield atPos(pos) { ValDef(newmods, name, tp.duplicate, rhs.duplicate) } } diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala index 1b5bd62ecd..e9061af154 100644 --- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala +++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala @@ -1,5 +1,6 @@ /* NSC -- new scala compiler * Copyright 2005-2007 LAMP/EPFL + * @author Nikolay Mihaylov */ // $Id$ @@ -12,7 +13,6 @@ import java.nio.{ByteBuffer, ByteOrder} import scala.collection.mutable.{Map, HashMap, HashSet, Stack} import scala.tools.nsc.symtab._ import scala.tools.nsc.util.Position -import compat.StringBuilder import ch.epfl.lamp.compiler.msil.{Type => MsilType, _} import ch.epfl.lamp.compiler.msil.emit._ @@ -277,7 +277,7 @@ abstract class GenMSIL extends SubComponent { val symtab: Array[Byte] = new Array[Byte](pickle.writeIndex + 8) symtab(0) = 1.toByte var size:Int = pickle.writeIndex - for(val i <- Iterator.range(2, 6)) { + for (i <- 2 until 6) { symtab(i) = (size & 0xff).toByte size = size >> 8 } @@ -298,7 +298,7 @@ abstract class GenMSIL extends SubComponent { if (settings.debug.value) log("creating attributes: " + attributes + " for member : " + member) - for(val AnnotationInfo(typ, consts, nvPairs) <- attributes /* !typ.symbol.hasFlag(Flags.JAVA) */ ) { + for (AnnotationInfo(typ, consts, nvPairs) <- attributes /* !typ.symbol.hasFlag(Flags.JAVA) */ ) { // assert(consts.length <= 1, // "too many constant arguments for attribute; "+consts.toString()) @@ -455,7 +455,7 @@ abstract class GenMSIL extends SubComponent { } private def createTypes(): Unit = - for (val sym <- classes.keys) { + for (sym <- classes.keys) { if (settings.debug.value) log("Calling CreatType for " + sym + ", " + types(sym)) types(sym).asInstanceOf[TypeBuilder].CreateType() @@ -554,7 +554,7 @@ abstract class GenMSIL extends SubComponent { } if (mcode != null) { - for (val local <- (m.locals.diff(m.params))) { + for (local <- m.locals.diff(m.params)) { if (settings.debug.value) log("add local var: " + local + ", of kind " + local.kind) val t: MsilType = msilType(local.kind) @@ -697,7 +697,7 @@ abstract class GenMSIL extends SubComponent { var res = "" res = res + TopBlock.indent + "BlockList0:\n" TopBlock.indent = TopBlock.indent + " " - for(val b <- blocks) + for (b <- blocks) res = res + b + "\n" TopBlock.indent = TopBlock.indent.substring(0,TopBlock.indent.length-2) res @@ -778,7 +778,7 @@ abstract class GenMSIL extends SubComponent { TopBlock.indent = TopBlock.indent.substring(0,TopBlock.indent.length-4) res = res + TopBlock.indent + " " + "catch:\n" TopBlock.indent = TopBlock.indent + " " - for(val b <- catchBlocks) + for (b <- catchBlocks) res = res + b + "\n" TopBlock.indent = TopBlock.indent.substring(0,TopBlock.indent.length-4) res = res + TopBlock.indent + " " + "finally:\n" @@ -887,9 +887,9 @@ abstract class GenMSIL extends SubComponent { } // get leaving blocks and their outside targets def leavingBlocks(blocks: List[BasicBlock]): List[(BasicBlock, List[BasicBlock])] = { - for {val b <- blocks + for {b <- blocks val t = outsideTargets(b, blocks) - t.length != 0 } yield (b, t) + if t.length != 0 } yield (b, t) } def replaceOutJumps(blocks: List[BasicBlock], leaving: List[(BasicBlock, List[BasicBlock])], exh: ExceptionHandler): (List[BasicBlock], Option[BasicBlock]) = { @@ -1064,20 +1064,20 @@ abstract class GenMSIL extends SubComponent { var orderedBlocks: List[BasicBlock] = Nil def flatten(block: Block): Unit = { if (block == TopBlock) { - for (val b <- TopBlock.blocks) flatten(b) + for (b <- TopBlock.blocks) flatten(b) } else block match { case cb: CodeBlock => orderedBlocks = orderedBlocks ::: cb.basicBlocks case bl: BlockList => - for (val b <- bl.blocks) flatten(b) + for (b <- bl.blocks) flatten(b) case cb: CatchBlock => - for (val b <- cb.blocks) flatten(b) + for (b <- cb.blocks) flatten(b) case eb: ExceptionBlock => val handler = eb.handler addExHInstruction(eb.tryBlock.firstBasicBlock, new BeginExceptionBlock(handler)) omitJump(eb.tryBlock.lastBasicBlock) flatten(eb.tryBlock) - for(val c <- eb.catchBlocks) { + for (c <- eb.catchBlocks) { val t: MsilType = (if (c.exSym == NoSymbol) EXCEPTION else getType(c.exSym)) addExHInstruction(c.firstBasicBlock, new BeginCatchBlock(handler, t)) @@ -1480,14 +1480,14 @@ abstract class GenMSIL extends SubComponent { mcode.Emit(OpCodes.Stloc, switchLocal) var i: Int = 0 - for(val l <- tags) { + for (l <- tags) { var targetLabel = labels(branches(i)) - for(val i <- l) { + for (i <- l) { mcode.Emit(OpCodes.Ldloc, switchLocal) loadI4(i, mcode) mcode.Emit(OpCodes.Beq, targetLabel) } - i = i + 1 + i += 1 } val defaultTarget = labels(branches(i)) if (nextBlock != defaultTarget && !omitJumpBlocks.contains(currentBlock)) @@ -1732,7 +1732,7 @@ abstract class GenMSIL extends SubComponent { def makeLabels(bs: List[BasicBlock]) = { if (settings.debug.value) log("Making labels for: " + method) - for (val bb <- bs) labels(bb) = mcode.DefineLabel() + for (bb <- bs) labels(bb) = mcode.DefineLabel() } ////////////////////// local vars /////////////////////// @@ -1747,21 +1747,21 @@ abstract class GenMSIL extends SubComponent { if (isStaticSymbol(m.symbol)) idx = 0 - for (val l <- params) { + for (l <- params) { if (settings.debug.value) log("Index value for parameter " + l + ": " + idx) l.index = idx - idx = idx + 1 // sizeOf(l.kind) + idx += 1 // sizeOf(l.kind) } val locvars = m.locals.diff(params) idx = 0 - for (val l <- locvars) { + for (l <- locvars) { if (settings.debug.value) log("Index value for local variable " + l + ": " + idx) l.index = idx - idx = idx + 1 // sizeOf(l.kind) + idx += 1 // sizeOf(l.kind) } } @@ -1899,7 +1899,7 @@ abstract class GenMSIL extends SubComponent { false } - for (val m <- cls.methods) { + for (m <- cls.methods) { if (isEntryPoint(m.symbol)) { if (entryPoint == null) entryPoint = m.symbol @@ -1977,7 +1977,7 @@ abstract class GenMSIL extends SubComponent { if (parents.length > 1) { if (settings.debug.value){ log("interfaces:") - for(val i <- Iterator.range(0, interfaces.length)){ + for (i <- Iterator.range(0, interfaces.length)){ log(" type: " + parents(i + 1).symbol + ", msil type: " + interfaces(i)) } } @@ -2002,7 +2002,7 @@ abstract class GenMSIL extends SubComponent { def createClassMembers0(iclass: IClass): Unit = { val mtype = getType(iclass.symbol).asInstanceOf[TypeBuilder] - for (val ifield <- iclass.fields) { + for (ifield <- iclass.fields) { val sym = ifield.symbol if (settings.debug.value) log("Adding field: " + sym.fullNameString) @@ -2014,7 +2014,7 @@ abstract class GenMSIL extends SubComponent { } if (iclass.symbol != definitions.ArrayClass) - for (val m: IMethod <- iclass.methods) { + for (m: IMethod <- iclass.methods) { val sym = m.symbol if (settings.debug.value) log("Creating MethodBuilder for " + Flags.flagsToString(sym.flags) + " " + @@ -2028,7 +2028,7 @@ abstract class GenMSIL extends SubComponent { if (m.symbol.isClassConstructor) { val constr = ownerType.DefineConstructor(attr, CallingConventions.Standard, paramTypes) - for (val i <- Iterator.range(0, paramTypes.length)) { + for (i <- Iterator.range(0, paramTypes.length)) { constr.DefineParameter(i, ParameterAttributes.None, msilName(m.params(i).sym)) } mapConstructor(sym, constr) @@ -2037,7 +2037,7 @@ abstract class GenMSIL extends SubComponent { var resType = msilType(m.returnType) val method = ownerType.DefineMethod(getMethodName(sym), attr, resType, paramTypes) - for (val i <- Iterator.range(0, paramTypes.length)){ + for (i <- Iterator.range(0, paramTypes.length)){ method.DefineParameter(i, ParameterAttributes.None, msilName(m.params(i).sym)) } if (!methods.contains(sym)) @@ -2145,15 +2145,15 @@ abstract class GenMSIL extends SubComponent { MOBJECT, MsilType.EmptyTypes) - for (val m <- sym.tpe.nonPrivateMembers; - m.owner != definitions.ObjectClass && !m.hasFlag(Flags.PROTECTED) && + for (m <- sym.tpe.nonPrivateMembers + if m.owner != definitions.ObjectClass && !m.hasFlag(Flags.PROTECTED) && m.isMethod && !m.isClassConstructor && !isStaticSymbol(m) && !m.hasFlag(Flags.CASE)) { if (settings.debug.value) log(" Mirroring method: " + m) val paramTypes = msilParamTypes(m) val paramNames: Array[String] = new Array[String](paramTypes.length) - for (val i <- Iterator.range(0, paramTypes.length)) + for (i <- 0 until paramTypes.length) paramNames(i) = "x_" + i // CHECK: verify if getMethodName is better than msilName @@ -2214,7 +2214,7 @@ abstract class GenMSIL extends SubComponent { "$delegateCaller$$" + nbDelegateCallers, MethodAttributes.Final | MethodAttributes.Public | MethodAttributes.Static, msilType(returnType), paramTypes.map(msilType).toArray) - for(val i <- Iterator.range(0, paramTypes.length)) + for (i <- 0 until paramTypes.length) caller.DefineParameter(i, ParameterAttributes.None, "arg" + i) val delegCtor = msilType(delegateType).GetConstructor(Array(MOBJECT, INT_PTR)) mcode.Emit(OpCodes.Ldnull) @@ -2226,7 +2226,7 @@ abstract class GenMSIL extends SubComponent { val functionApply: MethodInfo = getMethod(functionType.member(nme.apply)) val dcode: ILGenerator = caller.GetILGenerator() dcode.Emit(OpCodes.Ldsfld, anonfunField) - for(val i <- Iterator.range(0, paramTypes.length)) { + for (i <- 0 until paramTypes.length) { loadArg(dcode)(i) emitBox(dcode, toTypeKind(paramTypes(i))) } diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index ecca05b6c4..59a4523c3f 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -1,10 +1,19 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2007 LAMP/EPFL + * @author Burak Emir + */ +// $Id$ + package scala.tools.nsc.matching -import compat.StringBuilder import scala.tools.nsc.util.Position -/** utility methods (not just for ParallelMatching) */ -trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers with CodeFactory) { +/** Utility methods (not just for ParallelMatching). + * + * @author Burak Emir + */ +trait ParallelMatching { + self: transform.ExplicitOuter with PatternMatchers with CodeFactory => import global._ @@ -12,7 +21,7 @@ trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers wi // ---------------------------------- data sealed trait RuleApplication - case class ErrorRule extends RuleApplication + case class ErrorRule extends RuleApplication case class VariableRule(subst:List[Pair[Symbol,Symbol]], guard: Tree, body: Tree) extends RuleApplication def MixtureRule(scrutinee:Symbol, column:List[Tree], rest:Rep): MixtureRule = { @@ -337,14 +346,13 @@ trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers wi def combine(colcom: List[(Int,Set[Symbol])]): List[List[(Int,Symbol)]] = colcom match { case Nil => Nil case (i,syms)::Nil => syms.toList.map { sym => List((i,sym)) } - case (i,syms)::cs => for(val s <- syms.toList; val rest <- combine(cs)) yield (i,s) :: rest + case (i,syms)::cs => for (s <- syms.toList; rest <- combine(cs)) yield (i,s) :: rest } if(!sealedCols.isEmpty) { DEBUG("cols"+sealedCols) DEBUG("comb") - for(val com <- sealedComb) - DEBUG(com.toString) + for (com <- sealedComb) DEBUG(com.toString) val allcomb = combine(sealedCols zip sealedComb) //Console.println("all comb!" + allcomb) @@ -358,10 +366,9 @@ trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers wi val coversAll = allcomb forall { combination => row exists { r => covers(r._1, combination)}} //Console.println("all combinations covered? "+coversAll) if(!coversAll) { - val sb = new compat.StringBuilder() + val sb = new StringBuilder() sb.append("match is not exhaustive!\n") - for(val open <- allcomb; - !(row exists { r => covers(r._1, open)})) { + for (open <- allcomb if !(row exists { r => covers(r._1, open)})) { sb.append("missing combination ") val NPAD = 15 def pad(s:String) = { Iterator.range(1,NPAD - s.length).foreach { x => sb.append(" ") }; sb.append(s) } @@ -410,10 +417,10 @@ trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers wi val sb = new StringBuilder val NPAD = 15 def pad(s:String) = { Iterator.range(1,NPAD - s.length).foreach { x => sb.append(" ") }; sb.append(s) } - for(val tmp <- temp) pad(tmp.name.toString) + for (tmp <- temp) pad(tmp.name.toString) sb.append('\n') - for(val (r,i) <- row.zipWithIndex) { - for(val c <- r._1 ::: List(r._2, r._3)) { + for ((r,i) <- row.zipWithIndex) { + for (c <- r._1 ::: List(r._2, r._3)) { pad(c.toString) } sb.append('\n') @@ -556,20 +563,20 @@ trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers wi } def condition(tpe: Type, scrutineeTree: Tree): Tree = { - assert( tpe ne NoType ) + assert(tpe ne NoType) assert(scrutineeTree.tpe ne NoType) - if(tpe.isInstanceOf[SingletonType] && !tpe.isInstanceOf[ConstantType]) { - if(scrutineeTree.tpe <:< definitions.AnyRefClass.tpe) + if (tpe.isInstanceOf[SingletonType] && !tpe.isInstanceOf[ConstantType]) { + if (scrutineeTree.tpe <:< definitions.AnyRefClass.tpe) Eq(gen.mkAttributedRef(tpe.symbol), scrutineeTree) // object else Equals(gen.mkAttributedRef(tpe.symbol), scrutineeTree) // object - } else if(tpe.isInstanceOf[ConstantType]) { + } else if (tpe.isInstanceOf[ConstantType]) { val value = tpe.asInstanceOf[ConstantType].value //if(false && value.isInstanceOf[NamedConstant]) // Equals(Ident(scrut), value.asInstanceOf[NamedConstant].tree) // constant //assert(scrut.tpe <:< definitions.AnyRefClass.tpe, "stupid, should be caught by type checker "+value) //else - if(value == Constant(null) && scrutineeTree.tpe <:< definitions.AnyRefClass.tpe) + if (value == Constant(null) && scrutineeTree.tpe <:< definitions.AnyRefClass.tpe) Eq(scrutineeTree, Literal(value)) // constant else Equals(scrutineeTree, Literal(value)) // constant @@ -615,8 +622,8 @@ trait ParallelMatching requires (transform.ExplicitOuter with PatternMatchers wi theRef = handleOuter(theRef) val outerAcc = outerAccessor(tpe2test.symbol) - if(outerAcc == NoSymbol) { - if(settings.debug.value) cunit.warning(scrutinee.pos, "no outer acc for "+tpe2test.symbol) + if (outerAcc == NoSymbol) { + if (settings.debug.value) cunit.warning(scrutinee.pos, "no outer acc for "+tpe2test.symbol) cond } else And(cond, diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala index 601262b217..cb17975243 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala @@ -1,13 +1,12 @@ /* NSC -- new Scala compiler - * Copyright 2005-2006 LAMP/EPFL + * Copyright 2005-2007 LAMP/EPFL * @author Burak Emir */ // $Id$ package scala.tools.nsc.matching -import compat.StringBuilder -import scala.tools.nsc.util.{Position,NoPosition} +import scala.tools.nsc.util.{Position, NoPosition} /** This trait ... * @@ -167,7 +166,7 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes with P if(i != -1) { val CaseDef(_,_,b) = cases(i) DEBUG("*** damn, unreachable!") - //for(val b <- bodies) { + //for (b <- bodies) { // Console.println(b) //} cunit.error(b.pos, "unreachable code") @@ -205,7 +204,7 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes with P Console.println("****") Console.println("**** falling back, cause " + e.getMessage) Console.println("****") - for(val CaseDef(pat,guard,_) <- cases) + for (CaseDef(pat,guard,_) <- cases) Console.println(pat.toString) } } @@ -228,17 +227,17 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes with P case _h: Header => val h = _h.findLast; - // target.and is a header - // - //print() - //cunit.error(pat.pos, "duplicate case") - h.or = pDefaultPat(caseDef.pos, target.tpe) - h.or.and = pBody(caseDef.pos, env.getBoundVars(), guard, body) - //print() - //Console.println("tao = "+target.and.or) - //Console.println("tao = "+target.and.or.or) + // target.and is a header + // + //print() + //cunit.error(pat.pos, "duplicate case") + h.or = pDefaultPat(caseDef.pos, target.tpe) + h.or.and = pBody(caseDef.pos, env.getBoundVars(), guard, body) + //print() + //Console.println("tao = "+target.and.or) + //Console.println("tao = "+target.and.or.or) case _ => - Predef.error("overlapping match at unit = " + cunit + "; cdef = " + caseDef); + Predef.error("overlapping match at unit = " + cunit + "; cdef = " + caseDef) } } @@ -386,7 +385,7 @@ trait PatternMatchers requires (transform.ExplicitOuter with PatternNodes with P var i = 0; while (i < ts.length) { val target = enter1(ts(i), -1, subroot, subroot.casted, subenv) target.and = pBody(tree.pos) - i = i + 1 + i += 1 } pAltPat(tree.pos, subroot.and.asInstanceOf[Header]) /* @@ -622,7 +621,7 @@ print() } var i = 0; while (i < pats.length) { target = enter1(pats(i), i, target, casted, env) - i = i + 1 + i += 1 } target } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index 33ecdcb479..145c86a6bd 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -206,7 +206,7 @@ abstract class Pickler extends SubComponent { putRefTypes(formals); putType(restpe) case reflect.PolyType(typeParams, typeBounds, resultType) => putRefSymbols(typeParams) - for(val (t1,t2) <- typeBounds) { + for ((t1,t2) <- typeBounds) { putType(t1) putType(t2) } @@ -479,7 +479,7 @@ abstract class Pickler extends SubComponent { writeRef(sym) writeRef(ret) writeRef(rhs) - for(val vparams <- vparamss) { + for (vparams <- vparamss) { writeNat(vparams.length) writeRefs(vparams) } @@ -540,7 +540,7 @@ abstract class Pickler extends SubComponent { writeNat(POLYrtpe) writeRef(resultType) writeNat(typeBounds.length) - for(val (t1,t2) <- typeBounds) { + for ((t1,t2) <- typeBounds) { writeRef(t1) writeRef(t2) } diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala index 21e94a41ac..a77411093f 100644 --- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala +++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala @@ -98,8 +98,8 @@ abstract class LiftCode extends Transform { reflect.TypeApply(reify(fun), args map (.tpe) map reify) case Function(vparams, body) => - var env1 = env; - for (val vparam <- vparams) { + var env1 = env + for (vparam <- vparams) { val local = reflect.LocalValue( currentOwner, vparam.symbol.name.toString(), reify(vparam.symbol.tpe)); env1.update(vparam.symbol, local); @@ -142,7 +142,7 @@ abstract class LiftCode extends Transform { reflect.ClassDef(rsym, rtpe, rimp.asInstanceOf[reflect.Template]) case tmpl @ Template(parents, body) => - val rparents = for(val p <- parents) yield { reify(p.tpe) } + val rparents = for (p <- parents) yield { reify(p.tpe) } reflect.Template(rparents, body.map(reify)) case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) => @@ -266,7 +266,7 @@ abstract class LiftCode extends Transform { val name = className(c) if (name.length() == 0) throw new Error("don't know how to inject " + value) val injectedArgs = new ListBuffer[Tree] - for (val i <- 0 until c.productArity) + for (i <- 0 until c.productArity) injectedArgs += inject(c.productElement(i)) New(Ident(definitions.getClass(name)), List(injectedArgs.toList)) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 4624782479..f119288d54 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1,5 +1,5 @@ /* NSC -- new Scala compiler - * Copyright 2005-2006 LAMP/EPFL + * Copyright 2005-2007 LAMP/EPFL * @author Martin Odersky */ // $Id$ @@ -14,7 +14,8 @@ import symtab.Flags._ * @author Martin Odersky * @version 1.0 */ -trait Infer requires Analyzer { +trait Infer { + self: Analyzer => import global._ import definitions._ import posAssigner.atPos @@ -46,7 +47,7 @@ trait Infer requires Analyzer { } if (isVarArgs(formals1)) { val ft = formals1.last.normalize.typeArgs.head - formals1.init ::: (for (val i <- List.range(formals1.length - 1, nargs)) yield ft) + formals1.init ::: (for (i <- List.range(formals1.length - 1, nargs)) yield ft) } else formals1 } @@ -157,7 +158,7 @@ trait Infer requires Analyzer { val bound: Type = if (up) tparam.info.bounds.hi else tparam.info.bounds.lo // Console.println("solveOne0 "+tvar+" "+config+" "+bound);//DEBUG var cyclic = bound contains tparam - for (val (tvar2, (tparam2, variance2)) <- config) { + for ((tvar2, (tparam2, variance2)) <- config) { if (tparam2 != tparam && ((bound contains tparam2) || up && (tparam2.info.bounds.lo =:= tparam.tpe) || //@M TODO: might be affected by change to tpe in Symbol @@ -172,7 +173,7 @@ trait Infer requires Analyzer { tvar.constr.hibounds = bound.instantiateTypeParams(tparams, tvars) :: tvar.constr.hibounds } - for (val tparam2 <- tparams) + for (tparam2 <- tparams) if (tparam2.info.bounds.lo =:= tparam.tpe) //@M TODO: might be affected by change to tpe in Symbol tvar.constr.hibounds = tparam2.tpe.instantiateTypeParams(tparams, tvars) :: tvar.constr.hibounds @@ -181,7 +182,7 @@ trait Infer requires Analyzer { tvar.constr.lobounds = bound.instantiateTypeParams(tparams, tvars) :: tvar.constr.lobounds } - for (val tparam2 <- tparams) + for (tparam2 <- tparams) if (tparam2.info.bounds.hi =:= tparam.tpe) //@M TODO: might be affected by change to tpe in Symbol tvar.constr.lobounds = tparam2.tpe.instantiateTypeParams(tparams, tvars) :: tvar.constr.lobounds @@ -193,7 +194,7 @@ trait Infer requires Analyzer { assertNonCyclic(tvar)//debug } } - for (val (tvar, (tparam, variance)) <- config) + for ((tvar, (tparam, variance)) <- config) solveOne(tvar, tparam, variance) tvars map instantiate } @@ -310,9 +311,9 @@ trait Infer requires Analyzer { val syms1 = typeRefs.collect(tp1) val syms2 = typeRefs.collect(tp2) for { - val sym1 <- syms1 - val sym2 <- syms2 - sym1 != sym2 && sym1.toString == sym2.toString + sym1 <- syms1 + sym2 <- syms2 + if sym1 != sym2 && sym1.toString == sym2.toString } yield { val name = sym1.name explainName(sym1) @@ -324,7 +325,7 @@ trait Infer requires Analyzer { val result = op - for (val (sym1, sym2, name) <- patches) { + for ((sym1, sym2, name) <- patches) { sym1.name = name sym2.name = name } @@ -534,7 +535,7 @@ trait Infer requires Analyzer { throw new DeferredNoInstance(() => "result type " + normalize(restpe) + " is incompatible with expected type " + pt) } - for (val tvar <- tvars) + for (tvar <- tvars) if (!isFullyDefined(tvar)) tvar.constr.inst = NoType // Then define remaining type variables from argument types. @@ -700,16 +701,16 @@ trait Infer requires Analyzer { def varianceMismatches(as: Iterable[(Symbol, Symbol)]): unit = _varianceMismatches ++= as def stricterBounds(as: Iterable[(Symbol, Symbol)]): unit = _stricterBounds ++= as - for(val (hkarg, hkparam) <- hkargs zip hkparams) { - if(hkparam.typeParams.isEmpty) { // base-case: kind * - if(!variancesMatch(hkarg, hkparam)) + for ((hkarg, hkparam) <- hkargs zip hkparams) { + if (hkparam.typeParams.isEmpty) { // base-case: kind * + if (!variancesMatch(hkarg, hkparam)) varianceMismatch(hkarg, hkparam) // instantiateTypeParams(tparams, targs) --> higher-order bounds may contain references to type arguments // substSym(hkparams, hkargs) --> these types are going to be compared as types of kind * // --> their arguments use different symbols, but are conceptually the same // (could also replace the types by polytypes, but can't just strip the symbols, as ordering is lost then) - if(!(hkparam.info.instantiateTypeParams(tparams, targs).bounds.substSym(hkparams, hkargs) <:< hkarg.info.bounds)) + if (!(hkparam.info.instantiateTypeParams(tparams, targs).bounds.substSym(hkparams, hkargs) <:< hkarg.info.bounds)) stricterBound(hkarg, hkparam) } else { val (vm, sb) = checkKindBoundsHK(hkarg.typeParams, hkparam.typeParams) @@ -728,20 +729,23 @@ trait Infer requires Analyzer { else "invariant"; def qualify(a0: Symbol, b0: Symbol): String = if(a0.toString != b0.toString) "" else { - assert((a0 ne b0) && (a0.owner ne b0.owner)); var a=a0; var b=b0 - while(a.owner.name == b.owner.name) {a=a.owner; b=b.owner} - if(a.locationString ne "") " (" + a.locationString.trim + ")" else "" + assert((a0 ne b0) && (a0.owner ne b0.owner)); + var a = a0; var b = b0 + while (a.owner.name == b.owner.name) { a = a.owner; b = b.owner} + if (a.locationString ne "") " (" + a.locationString.trim + ")" else "" } val errors = new ListBuffer[String] (tparams zip targs).foreach{ case (tparam, targ) if(targ.isHigherKinded) => val (varianceMismatches, stricterBounds) = checkKindBoundsHK(targ.typeParams, tparam.typeParams) - if(!(varianceMismatches.isEmpty && stricterBounds.isEmpty)){ + if (!(varianceMismatches.isEmpty && stricterBounds.isEmpty)){ errors += (targ+"'s type parameters do not match "+tparam+"'s expected parameters: "+ - (for(val (a,p) <- varianceMismatches) yield a+qualify(a,p)+ " is "+varStr(a)+", but "+ + (for ((a, p) <- varianceMismatches) + yield a+qualify(a,p)+ " is "+varStr(a)+", but "+ p+qualify(p,a)+" is declared "+varStr(p)).toList.mkString("", ", ", "") + - (for(val (a,p) <- stricterBounds) yield a+qualify(a,p)+"'s bounds "+a.info+" are stricter than "+ + (for ((a, p) <- stricterBounds) + yield a+qualify(a,p)+"'s bounds "+a.info+" are stricter than "+ p+qualify(p,a)+"'s declared bounds "+p.info).toList.mkString("", ", ", "")) } case _ => @@ -962,7 +966,7 @@ trait Infer requires Analyzer { else if (sym == AllClass || sym == AllRefClass) error(pos, "this type cannot be used in a type pattern") else - for (val arg <- args) { + for (arg <- args) { if (sym == ArrayClass) checkCheckable(pos, arg) else arg match { case TypeRef(_, sym, _) if isLocalBinding(sym) => @@ -973,7 +977,7 @@ trait Infer requires Analyzer { } checkCheckable(pos, pre) case RefinedType(parents, decls) => - if (decls.isEmpty) for (val p <- parents) checkCheckable(pos, p) + if (decls.isEmpty) for (p <- parents) checkCheckable(pos, p) else patternWarning(tp, "refinement ") case ThisType(_) => ; @@ -984,8 +988,8 @@ trait Infer requires Analyzer { } } - /** Type intersection of simple type `tp1' with general type `tp2' - * The result eliminates some redundancies + /** Type intersection of simple type <code>tp1</code> with general + * type <code>tp2</code>. The result eliminates some redundancies. */ def intersect(tp1: Type, tp2: Type): Type = { if (tp1 <:< tp2) tp1 @@ -1081,7 +1085,8 @@ trait Infer requires Analyzer { /** A traverser to collect type parameters referred to in a type */ object freeTypeParamsOfTerms extends SymCollector { - protected def includeCondition(sym: Symbol): boolean = sym.isAbstractType && sym.owner.isTerm + protected def includeCondition(sym: Symbol): boolean = + sym.isAbstractType && sym.owner.isTerm } object typeRefs extends SymCollector { @@ -1098,7 +1103,7 @@ trait Infer requires Analyzer { def checkNotShadowed(pos: Position, pre: Type, best: Symbol, eligible: List[Symbol]) = if (!phase.erasedTypes) - for (val alt <- eligible) { + for (alt <- eligible) { if (alt.owner != best.owner && alt.owner.isSubClass(best.owner)) error(pos, "erroneous reference to overloaded definition,\n"+ diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 9adfbe07fc..cc89c8e623 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1,5 +1,5 @@ /* NSC -- new Scala compiler - * Copyright 2005-2006 LAMP/EPFL + * Copyright 2005-2007 LAMP/EPFL * @author Martin Odersky */ // $Id$ @@ -210,7 +210,7 @@ trait Namers requires Analyzer { def enterSyms(trees: List[Tree]): Namer = { var namer : Namer = this - for (val tree <- trees) { + for (tree <- trees) { val txt = namer.enterSym(tree) if (!(txt eq namer.context)) namer = new Namer(txt) } @@ -232,7 +232,7 @@ trait Namers requires Analyzer { */ def skolemize(tparams: List[AbsTypeDef]): unit = { val tskolems = newTypeSkolems(tparams map (.symbol)) - for (val (tparam, tskolem) <- tparams zip tskolems) tparam.symbol = tskolem + for ((tparam, tskolem) <- tparams zip tskolems) tparam.symbol = tskolem } def applicableTypeParams(owner: Symbol): List[Symbol] = @@ -241,14 +241,12 @@ trait Namers requires Analyzer { def deSkolemize: TypeMap = new DeSkolemizeMap(applicableTypeParams(context.owner)) - - private def doLateParams = if(!lateParams.isEmpty) { - val todo = lateParams.toList - lateParams.clear - for(val rec <- todo) { - rec._1.finishWith0(rec._2, rec._3, rec._4) - } - } + private def doLateParams = if (!lateParams.isEmpty) { + val todo = lateParams.toList + lateParams.clear + for (rec <- todo) + rec._1.finishWith0(rec._2, rec._3, rec._4) + } private def finishWith0(sym: Symbol, tree: Tree, tparams: List[AbsTypeDef]): unit = { if (settings.debug.value) log("entered " + sym + " in " + context.owner + ", scope-id = " + context.scope.hashCode()); @@ -519,7 +517,7 @@ trait Namers requires Analyzer { // fill in result type and parameter types from overridden symbol if there is a unique one. if (meth.owner.isClass && (tpt.isEmpty || vparamss.exists(.exists(.tpt.isEmpty)))) { // try to complete from matching definition in base type - for (val vparams <- vparamss; val vparam <- vparams) + for (vparams <- vparamss; vparam <- vparams) if (vparam.tpt.isEmpty) vparam.symbol setInfo WildcardType val overridden = overriddenSymbol if (overridden != NoSymbol && !(overridden hasFlag OVERLOADED)) { @@ -528,9 +526,9 @@ trait Namers requires Analyzer { case mt => mt } - for (val vparams <- vparamss) { + for (vparams <- vparamss) { var pfs = resultPt.paramTypes - for (val vparam <- vparams) { + for (vparam <- vparams) { if (vparam.tpt.isEmpty) { vparam.tpt.tpe = pfs.head vparam.symbol setInfo pfs.head @@ -556,7 +554,7 @@ trait Namers requires Analyzer { .info.isInstanceOf[MethodType])) { vparamSymss = List(List()) } - for (val vparams <- vparamss; val vparam <- vparams; vparam.tpt.isEmpty) { + for (vparams <- vparamss; vparam <- vparams if vparam.tpt.isEmpty) { context.error(vparam.pos, "missing parameter type") vparam.tpt.tpe = ErrorType } @@ -594,7 +592,7 @@ trait Namers requires Analyzer { if (sym hasFlag IMPLICIT) { val p = provided(tp); //Console.println("check contractive: "+sym+" "+p+"/"+required(tp)) - for (val r <- required(tp)) { + for (r <- required(tp)) { if (!isContainedIn(r, p) || (r =:= p)) { context.error(sym.pos, "implicit " + sym + " is not contractive," + "\n because the implicit parameter type " + r + @@ -627,9 +625,9 @@ trait Namers requires Analyzer { tree match { case defn: MemberDef => val ainfos = for { - val annot <- defn.mods.annotations + annot <- defn.mods.annotations val ainfo = typer.typedAnnotation(annot, typer.getConstant) - !ainfo.atp.isError + if !ainfo.atp.isError } yield ainfo if (!ainfos.isEmpty) { val annotated = if (sym.isModule) sym.moduleClass else sym diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 10c7818e6e..c395acc60b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -81,7 +81,7 @@ trait SyntheticMethods requires Analyzer { //val retTpe = lub(accs map (.tpe.resultType)) val method = syntheticMethod(nme.productElement, FINAL, MethodType(List(IntClass.tpe), AnyClass.tpe/*retTpe*/)) typed(DefDef(method, vparamss => Match(Ident(vparamss.head.head), { - (for((sym,i) <- accs.zipWithIndex) yield { + (for ((sym,i) <- accs.zipWithIndex) yield { CaseDef(Literal(Constant(i)),EmptyTree, Ident(sym)) }):::List(CaseDef(Ident(nme.WILDCARD), EmptyTree, Throw(New(TypeTree(IndexOutOfBoundsExceptionClass.tpe), List(List( |