summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2006-11-07 10:34:23 +0000
committermichelou <michelou@epfl.ch>2006-11-07 10:34:23 +0000
commit84089c19ec1707d3fa3e37c6218cb990013d4066 (patch)
treeb1f0291fa740d4bebfca0ddd506fdd9ad6d01ec3
parent63d618b20c238f5963c034afd96cb0bd34a73d14 (diff)
downloadscala-84089c19ec1707d3fa3e37c6218cb990013d4066.tar.gz
scala-84089c19ec1707d3fa3e37c6218cb990013d4066.tar.bz2
scala-84089c19ec1707d3fa3e37c6218cb990013d4066.zip
removed leading/trailing tabs/blanks in typeche...
removed leading/trailing tabs/blanks in typechecker/Typers.scala
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala189
1 files changed, 145 insertions, 44 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index e7620ce54c..db13b4e168 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -132,6 +132,13 @@ trait Typers requires Analyzer {
)
}
+ /**
+ * @param pos ...
+ * @param from ...
+ * @param to ...
+ * @param reportAmbiguous ...
+ * @return ...
+ */
private def inferView(pos: PositionType, from: Type, to: Type, reportAmbiguous: boolean): Tree = {
if (settings.debug.value) log("infer view from "+from+" to "+to)//debug
if (phase.id > currentRun.typerPhase.id) EmptyTree
@@ -149,6 +156,14 @@ trait Typers requires Analyzer {
}
}
+ /**
+ * @param pos ...
+ * @param from ...
+ * @param name ...
+ * @param tp ...
+ * @param reportAmbiguous ...
+ * @return ...
+ */
private def inferView(pos: PositionType, from: Type, name: Name, tp: Type, reportAmbiguous: boolean): Tree = {
val to = refinedType(List(WildcardType), NoSymbol)
val psym = (if (name.isTypeName) to.symbol.newAbstractType(pos, name)
@@ -199,12 +214,19 @@ trait Typers requires Analyzer {
}
/** Check that <code>tree</code> is a stable expression.
+ *
+ * @param tree ...
+ * @return ...
*/
def checkStable(tree: Tree): Tree =
if (treeInfo.isPureExpr(tree)) tree
else errorTree(tree, "stable identifier required, but " + tree + " found.")
- /** Check that type `tp' is not a subtype of itself.
+ /** Check that type <code>tp</code> is not a subtype of itself.
+ *
+ * @param pos ...
+ * @param tp ...
+ * @return <code>true</code> if <code>tp</code> is not a subtype of itself.
*/
def checkNonCyclic(pos: PositionType, tp: Type): boolean = {
def checkNotLocked(sym: Symbol): boolean = {
@@ -391,10 +413,14 @@ trait Typers requires Analyzer {
}
}
- /** Post-process an identifier or selection node, performing the following:
- * (1) Check that non-function pattern expressions are stable
- * (2) Check that packages and static modules are not used as values
- * (3) Turn tree type into stable type if possible and required by context.
+ /** <p>
+ * Post-process an identifier or selection node, performing the following:
+ * </p>
+ * <ol>
+ * <!--(1)--><li>Check that non-function pattern expressions are stable</li>
+ * <!--(2)--><li>Check that packages and static modules are not used as values</li>
+ * <!--(3)--><li>Turn tree type into stable type if possible and required by context.</li>
+ * </ol>
*/
private def stabilize(tree: Tree, pre: Type, mode: int, pt: Type): Tree = {
if (tree.symbol.hasFlag(OVERLOADED) && (mode & FUNmode) == 0)
@@ -551,7 +577,7 @@ trait Typers requires Analyzer {
setError(tree)
}
} else if (settings.Xunapply.value) { /*unapply (5.3beta) */
- // fix symbol -- we are using the module not the class
+ // fix symbol -- we are using the module not the class
val consp = if(clazz.isModule) clazz else {
val obj = clazz.linkedModuleOfClass
if (obj != NoSymbol) tree.setSymbol(obj)
@@ -631,6 +657,12 @@ trait Typers requires Analyzer {
// adapt(tree, mode, pt)
// }
+ /**
+ * @param tree ...
+ * @param mode ...
+ * @param pt ...
+ * @return ...
+ */
def instantiate(tree: Tree, mode: int, pt: Type): Tree = {
val tparams = context.undetparams
context.undetparams = List()
@@ -713,15 +745,19 @@ trait Typers requires Analyzer {
List(TypeTree(AnyRefClass.tpe))
}
- /** Check that
- * - all parents are class types,
- * - first parent cluss is not a mixin; following classes are mixins,
- * - final classes are not inherited,
- * - sealed classes are only inherited by classes which are
- * nested within definition of base class, or that occur within same
- * statement sequence,
- * - self-type of current class is a subtype of self-type of each parent class.
- * - no two parents define same symbol.
+ /** <p>Check that</p>
+ * <ul>
+ * <li>all parents are class types,</li>
+ * <li>first parent cluss is not a mixin; following classes are mixins,</li>
+ * <li>final classes are not inherited,</li>
+ * <li>
+ * sealed classes are only inherited by classes which are
+ * nested within definition of base class, or that occur within same
+ * statement sequence,
+ * </li>
+ * <li>self-type of current class is a subtype of self-type of each parent class.</li>
+ * <li>no two parents define same symbol.</li>
+ * </ul>
*/
def validateParentClasses(parents: List[Tree], selfType: Type): unit = {
@@ -798,6 +834,10 @@ trait Typers requires Analyzer {
copy.ModuleDef(mdef, mdef.mods, mdef.name, impl2) setType NoType
}
+ /**
+ * @param stat ...
+ * @return ...
+ */
def addGetterSetter(stat: Tree): List[Tree] = stat match {
case ValDef(mods, name, tpt, rhs)
if !(mods hasFlag LOCAL) && !stat.symbol.isModuleVar =>
@@ -950,6 +990,10 @@ trait Typers requires Analyzer {
}
}
+ /**
+ * @param ddef ...
+ * @return ...
+ */
def typedDefDef(ddef: DefDef): DefDef = {
attributes(ddef)
@@ -1043,6 +1087,10 @@ trait Typers requires Analyzer {
copy.LabelDef(ldef, ldef.name, ldef.params, rhs1) setType restpe
}
+ /**
+ * @param clazz ...
+ * @return ...
+ */
def anonymousClassRefinement(clazz: Symbol): Type = {
val tp = refinedType(clazz.info.parents, clazz.owner)
val thistp = tp.symbol.thisType
@@ -1056,6 +1104,12 @@ trait Typers requires Analyzer {
tp
}
+ /**
+ * @param block ...
+ * @param mode ...
+ * @param pt ...
+ * @return ...
+ */
def typedBlock(block: Block, mode: int, pt: Type): Block = {
if (context.retyping) {
for (val stat <- block.stats) {
@@ -1077,6 +1131,12 @@ trait Typers requires Analyzer {
}
}
+ /**
+ * @param cdef ...
+ * @param pattpe ...
+ * @param pt ...
+ * @return ...
+ */
def typedCase(cdef: CaseDef, pattpe: Type, pt: Type): CaseDef = {
val pat1: Tree = typedPattern(cdef.pat, pattpe)
val guard1: Tree = if (cdef.guard == EmptyTree) EmptyTree
@@ -1112,6 +1172,12 @@ trait Typers requires Analyzer {
*/
}
+ /**
+ * @param fun ...
+ * @param mode ...
+ * @param pt ...
+ * @return ...
+ */
def typedFunction(fun: Function, mode: int, pt: Type): Tree = {
val codeExpected = !forCLDC && (pt.symbol isNonBottomSubClass CodeClass)
@@ -1127,7 +1193,7 @@ trait Typers requires Analyzer {
val Triple(clazz, argpts, respt) = decompose(if (codeExpected) pt.typeArgs.head else pt)
if (fun.vparams.length != argpts.length)
- errorTree(fun, "wrong number of parameters; expected = "+argpts.length)
+ errorTree(fun, "wrong number of parameters; expected = " + argpts.length)
else {
val vparamSyms = List.map2(fun.vparams, argpts) { (vparam, argpt) =>
if (vparam.tpt.isEmpty)
@@ -1236,8 +1302,16 @@ trait Typers requires Analyzer {
List.map2(args, adaptedFormals)((arg, formal) => typedArg(arg, mode, 0, formal))
}
+ /**
+ * @param tree ...
+ * @param fun0 ...
+ * @param args ...
+ * @param mode ...
+ * @param pt ...
+ * @return ...
+ */
def typedApply(tree: Tree, fun0: Tree, args: List[Tree], mode: int, pt: Type): Tree = {
- var fun = fun0;
+ var fun = fun0
if (fun.hasSymbol && (fun.symbol hasFlag OVERLOADED)) {
// preadapt symbol to number of arguments given
val argtypes = args map (arg => AllClass.tpe)
@@ -1310,8 +1384,8 @@ trait Typers requires Analyzer {
}
case ErrorType =>
setError(copy.Apply(tree, fun, args))
- /* --- begin unapply --- */
- case otpe if definitions.unapplyMember(otpe).exists && settings.Xunapply.value =>
+ /* --- begin unapply --- */
+ case otpe if definitions.unapplyMember(otpe).exists && settings.Xunapply.value =>
// !!! this is fragile, maybe needs to be revised when unapply patterns become terms
val unapp = definitions.unapplyMember(otpe)
assert(unapp.exists, tree)
@@ -1324,26 +1398,25 @@ trait Typers requires Analyzer {
val arg = Ident(argDummy) setType pt
var prod: Type = null
-
- if(nme.unapplySeq == unapp.name) {
- def failSeq = {
- error(fun.pos, " unapplySeq should return Option[T] for T<:Product?[...Seq[?]]");
- setError(tree)
- }
- unapp.tpe.resultType match { // last should be seq...
+ if (nme.unapplySeq == unapp.name) {
+ def failSeq = {
+ error(fun.pos, " unapplySeq should return Option[T] for T<:Product?[...Seq[?]]")
+ setError(tree)
+ }
+ unapp.tpe.resultType match { // last should be seq...
case TypeRef(_, opt, List(tpe)) if opt == definitions.OptionClass =>
// the following is almost definitions.optionOfProductElems, but error handling?
tpe.baseClasses.find { x => isProductType(x.tpe) } match {
case Some(p) =>
val xs = tpe.baseType(p).typeArgs
if(xs.isEmpty)
- return failSeq
+ return failSeq
prod = productType((xs.tail map {x => WildcardType}) ::: List(seqType(WildcardType)))
- case None => return failSeq
+ case None => return failSeq
}
case _ => return failSeq
- }
- } else if (args.length == 0) prod = UnitClass.tpe
+ }
+ } else if (args.length == 0) prod = UnitClass.tpe
else prod = productType(args map (arg => WildcardType))
val funPt = appliedType(OptionClass.typeConstructor, List(prod))
@@ -1363,6 +1436,9 @@ trait Typers requires Analyzer {
}
}
+ /**
+ * @param defn ...
+ */
protected def attributes(defn: MemberDef): Unit = {
var attrError: Boolean = false;
def getConstant(tree: Tree): Constant = tree match {
@@ -1423,7 +1499,12 @@ trait Typers requires Analyzer {
defn.mods setAttr List();
}
-
+ /**
+ * @param tree ...
+ * @param mode ...
+ * @param pt ...
+ * @return ...
+ */
protected def typed1(tree: Tree, mode: int, pt: Type): Tree = {
//Console.println("typed1("+tree.getClass()+","+Integer.toHexString(mode)+","+pt+")")
def ptOrLub(tps: List[Type]) = if (isFullyDefined(pt)) pt else lub(tps)
@@ -1451,6 +1532,10 @@ trait Typers requires Analyzer {
errorTree(tree, treeSymTypeMsg(fun)+" does not take type parameters.")
}
+ /**
+ * @param args ...
+ * @return ...
+ */
def tryTypedArgs(args: List[Tree]) = {
try {
val c = context.makeSilent(false)
@@ -1529,8 +1614,12 @@ trait Typers requires Analyzer {
}
}
*/
- /** Attribute a selection where <code>tree</code> is `qual.name'.
+ /** Attribute a selection where <code>tree</code> is <code>qual.name</code>.
* <code>qual</code> is already attributed.
+ *
+ * @param qual ...
+ * @param name ...
+ * @return ...
*/
def typedSelect(qual: Tree, name: Name): Tree = {
val sym =
@@ -1581,7 +1670,11 @@ trait Typers requires Analyzer {
}
}
- /** does given name name an identifier visible at this point? */
+ /** does given name name an identifier visible at this point?
+ *
+ * @param name the given name
+ * @return <code>true</code> if an identifier with the given name is visible.
+ */
def namesSomeIdent(name: Name): boolean = {
var cx = context
while (cx != NoContext) {
@@ -1602,6 +1695,7 @@ trait Typers requires Analyzer {
}
/** Attribute an identifier consisting of a simple name or an outer reference.
+ *
* @param tree The tree representing the identifier.
* @param name The name of the identifier.
* Transformations: (1) Prefix class members with this.
@@ -1660,18 +1754,18 @@ trait Typers requires Analyzer {
if(!defSym.exists && !impSym.exists && name.isTypeName && (mode & PATTERNmode) != 0) {
typedIdent(name.toTermName) match {
case t if t.symbol.isTerm /*isModule*/ =>
- //Console.println("special treatment for "+name+" yields "+t)
- t.tpe match {
- case PolyType(_,MethodType(_,_)) =>
- //Console.println("ugh!")
- // for instance Predef.Pair
- //Console.println("no special treatment for "+name)
+ //Console.println("special treatment for "+name+" yields "+t)
+ t.tpe match {
+ case PolyType(_,MethodType(_,_)) =>
+ //Console.println("ugh!")
+ // for instance Predef.Pair
+ //Console.println("no special treatment for "+name)
case _ =>
//return t
defSym = t.symbol
- }
- case _ =>
- Console.println("no special treatment for "+name)
+ }
+ case _ =>
+ Console.println("no special treatment for "+name)
// when can this happen?
}
}
@@ -1703,7 +1797,7 @@ trait Typers requires Analyzer {
if (imports1.head.isExplicitImport(name)) {
if (imports.head.isExplicitImport(name) ||
imports1.head.depth != imports.head.depth) ambiguousImport()
- impSym = impSym1;
+ impSym = impSym1
imports = imports1
} else if (!imports.head.isExplicitImport(name) &&
imports1.head.depth == imports.head.depth) ambiguousImport()
@@ -1993,7 +2087,8 @@ trait Typers requires Analyzer {
else {
val ps = clazz.info.parents filter (p => p.symbol.name == mix)
if (ps.isEmpty) {
- if (settings.debug.value) Console.println(clazz.info.parents map (.symbol.name));//debug
+ if (settings.debug.value)
+ Console.println(clazz.info.parents map (.symbol.name))//debug
error(tree.pos, ""+mix+" does not name a parent class of "+clazz)
ErrorType
} else if (ps.tail.isEmpty) {
@@ -2099,6 +2194,12 @@ trait Typers requires Analyzer {
}
}
+ /**
+ * @param tree ...
+ * @param mode ...
+ * @param pt ...
+ * @return ...
+ */
def typed(tree: Tree, mode: int, pt: Type): Tree =
try {
if (settings.debug.value)