removed warnings.. (hello guys)

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@12323 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
michelou 2007-07-16 13:46:55 +00:00
parent 227fef124f
commit 4fb2e7a620
7 changed files with 228 additions and 202 deletions

View File

@ -58,7 +58,7 @@ abstract class DocDriver extends ModelFrames with ModelToXML {
for (p <- allClasses; d <- p._2) {
symbols += d.sym
for (pp <- d.sym.tpe.parents) subClasses(pp.symbol) += d
for (pp <- d.sym.tpe.parents) subClasses(pp.typeSymbol) += d
}
additions0.init
copyResources
@ -220,39 +220,45 @@ abstract class DocDriver extends ModelFrames with ModelToXML {
}
return false;
}
def aref(href: String, label: String)(implicit frame: Frame) =
frame.aref(href, "_self", label)
protected def anchor(entity: Symbol)(implicit frame: Frame): NodeSeq =
<a name={Text(frame.docName(entity))}></a>
object symbols extends jcl.LinkedHashSet[Symbol];
object allClasses extends jcl.LinkedHashMap[Package,jcl.LinkedHashSet[ClassOrObject]] {
override def default(pkg : Package) : jcl.LinkedHashSet[ClassOrObject] = {
object ret extends jcl.LinkedHashSet[ClassOrObject];
this(pkg) = ret; ret;
object symbols extends jcl.LinkedHashSet[Symbol]
object allClasses extends jcl.LinkedHashMap[Package, jcl.LinkedHashSet[ClassOrObject]] {
override def default(pkg: Package): jcl.LinkedHashSet[ClassOrObject] = {
object ret extends jcl.LinkedHashSet[ClassOrObject]
this(pkg) = ret
ret
}
}
object subClasses extends jcl.LinkedHashMap[Symbol,jcl.LinkedHashSet[ClassOrObject]] {
override def default(key : Symbol) = {
val ret = new jcl.LinkedHashSet[ClassOrObject];
this(key) = ret; ret;
object subClasses extends jcl.LinkedHashMap[Symbol, jcl.LinkedHashSet[ClassOrObject]] {
override def default(key: Symbol) = {
val ret = new jcl.LinkedHashSet[ClassOrObject]
this(key) = ret
ret
}
}
override def rootFor(sym : Symbol) : String = {
assert(sym != NoSymbol);
if (sym.toplevelClass == NoSymbol) return super.rootFor(sym);
if (symbols.contains(sym.toplevelClass)) return super.rootFor(sym);
val clazz = sym.toplevelClass.asInstanceOf[ClassSymbol];
override def rootFor(sym: Symbol): String = {
assert(sym != NoSymbol)
if (sym.toplevelClass == NoSymbol) return super.rootFor(sym)
if (symbols.contains(sym.toplevelClass)) return super.rootFor(sym)
val clazz = sym.toplevelClass.asInstanceOf[ClassSymbol]
import scala.tools.nsc.io._;
clazz.classFile match {
case file : ZipArchive#FileEntry =>
val key = keyFor(file.archive);
val key = keyFor(file.archive)
if (key != null && roots.contains(key)) {
return roots(key) + '/';
return roots(key) + '/'
}
case _ => ;
case _ =>
}
return super.rootFor(sym);
super.rootFor(sym)
}
}

View File

@ -19,7 +19,7 @@ trait ModelExtractor {
val global: Global
import global._
def assert(b : Boolean) {
def assert(b: Boolean) {
if (!b)
throw new Error;
}
@ -108,7 +108,7 @@ trait ModelExtractor {
sym.privateWithin.nameString;
else null;
});
def f(flag : Int, str : String) =
def f(flag: Int, str: String) =
if (sym.hasFlag(flag)) string = string + " " + str;
f(Flags.IMPLICIT, "implicit");
@ -120,22 +120,21 @@ trait ModelExtractor {
if (!sym.isTrait) f(Flags.DEFERRED, "abstract");
string.trim;
}
def listName = name;
def name = sym.nameString;
def fullName(sep : Char) = sym.fullNameString(sep);
def kind : String;
def header = {
}
def typeParams : List[TypeParam] = Nil
def listName = name
def name = sym.nameString
def fullName(sep: Char) = sym.fullNameString(sep)
def kind: String
def header { }
def typeParams: List[TypeParam] = Nil
def params: List[List[Param]] = Nil
def resultType: Option[Type] = None
def parents: Iterable[Type] = Nil
def lo: Option[Type] = sym.info match {
case TypeBounds(lo,hi) if decode(lo.symbol) != definitions.AllClass => Some(lo);
case _ => None;
case TypeBounds(lo,hi) if decode(lo.typeSymbol) != definitions.AllClass => Some(lo)
case _ => None
}
def hi : Option[Type] = sym.info match {
case TypeBounds(lo,hi) if decode(hi.symbol) != definitions.AnyClass => Some(hi)
case TypeBounds(lo,hi) if decode(hi.typeSymbol) != definitions.AnyClass => Some(hi)
case _ => None
}
def variance = {
@ -154,7 +153,7 @@ trait ModelExtractor {
}
class ConstructorParam(sym: Symbol) extends Param(sym) {
override protected def accessQualified(core : String, qual : String) = core match {
override protected def accessQualified(core: String, qual: String) = core match {
case "public" => "val"
case "protected" => super.accessQualified(core,qual) + " val"
case "private" if qual == "this" => ""
@ -203,7 +202,7 @@ trait ModelExtractor {
pA = pA.tail;
pB = pB.tail;
}
return 0;
0
}
trait ClassOrObject extends Entity {
@ -218,7 +217,7 @@ trait ModelExtractor {
sym.constrParamAccessors.foreach(arg => {
val str = symtab.Flags.flagsToString(arg.flags);
assert(arg.hasFlag(symtab.Flags.PRIVATE) && arg.hasFlag(symtab.Flags.LOCAL));
val argName = arg.name.toString.trim;
val argName = arg.name.toString.trim
val actual = sym.tpe.decls.elements.find(e => {
val eName = e.name.toString.trim;
argName == eName && {
@ -238,15 +237,14 @@ trait ModelExtractor {
}
});
}
def members0(f : Symbol => Boolean) = decls.projection.filterKeys(f).valueSet;
def members(c : Category) : Iterable[Member] = members0(c.f);
object inherited extends jcl.LinkedHashMap[Symbol,List[Member]]() {
override def default(tpe : Symbol) = Nil;
{
def members0(f: Symbol => Boolean) = decls.projection.filterKeys(f).valueSet
def members(c: Category): Iterable[Member] = members0(c.f)
object inherited extends jcl.LinkedHashMap[Symbol, List[Member]]() {
override def default(tpe: Symbol) = Nil
for (m <- sym.tpe.members if !sym.tpe.decls.elements.contains(m) &&
(Values.f(m) || Methods.f(m))) {
val o = m.overridingSymbol(sym)
if ((o == NoSymbol)) {
if (o == NoSymbol) {
val parent = decode(m.enclClass)
val mo = Member(m)
if (!mo.isEmpty) {
@ -255,24 +253,24 @@ trait ModelExtractor {
}
}
}
}
override def parents = freshParents;
abstract class Member(sym : Symbol) extends Entity(sym) {
private def overriding = sym.allOverriddenSymbols;
override def parents = freshParents
abstract class Member(sym: Symbol) extends Entity(sym) {
private def overriding = sym.allOverriddenSymbols
override def comment = super.comment match {
case ret @ Some(comment) => ret;
case ret @ Some(comment) =>
ret
case None =>
val o = overriding.find(comments.contains);
o.map(comments.apply);
val o = overriding.find(comments.contains)
o.map(comments.apply)
}
}
abstract class ValDef(sym: Symbol) extends Member(sym) {
override def resultType = Some(resultType0);
override def resultType = Some(resultType0)
protected def resultType0: Type
override def overridden: Iterable[Symbol] = {
var ret : jcl.LinkedHashSet[Symbol] = null;
var ret: jcl.LinkedHashSet[Symbol] = null
for (parent <- ClassOrObject.this.parents) {
val sym0 = sym.overriddenSymbol(parent.symbol);
val sym0 = sym.overriddenSymbol(parent.typeSymbol)
if (sym0 != NoSymbol) {
if (ret == null) ret = new jcl.LinkedHashSet[Symbol];
ret += sym0;

View File

@ -37,27 +37,28 @@ trait ModelToXML extends ModelExtractor {
if (definitions.isFunctionType(tpe)) {
val (args,r) = tpe.normalize.typeArgs.splitAt(tpe.normalize.typeArgs.length - 1);
args.mkXML("(", ", ", ")")(link) ++ Text(" => ") ++ link(r.head);
} else if (tpe.symbol == definitions.RepeatedParamClass) {
assert(tpe.typeArgs.length == 1);
link(tpe.typeArgs(0)) ++ Text("*");
} else if (tpe.symbol == definitions.ByNameParamClass) {
assert(tpe.typeArgs.length == 1);
Text("=> ") ++ link(tpe.typeArgs(0));
} else if (tpe.symbol.name.toString.startsWith("Tuple") &&
tpe.symbol.owner.name == nme.scala_.toTypeName) {
tpe.typeArgs.mkXML("(", ", ", ")")(link);
} else link(decode(tpe.symbol)) ++ tpe.typeArgs.surround("[", "]")(link);
} else if (tpe.typeSymbol == definitions.RepeatedParamClass) {
assert(tpe.typeArgs.length == 1)
link(tpe.typeArgs(0)) ++ Text("*")
} else if (tpe.typeSymbol == definitions.ByNameParamClass) {
assert(tpe.typeArgs.length == 1)
Text("=> ") ++ link(tpe.typeArgs(0))
} else if (tpe.typeSymbol.name.toString.startsWith("Tuple") &&
tpe.typeSymbol.owner.name == nme.scala_.toTypeName) {
tpe.typeArgs.mkXML("(", ", ", ")")(link)
} else
link(decode(tpe.typeSymbol)) ++ tpe.typeArgs.surround("[", "]")(link)
} else tpe match {
case PolyType(tparams,result) =>
link(result) ++ tparams.surround("[", "]")(link);
link(result) ++ tparams.surround("[", "]")(link)
case RefinedType(parents,_) =>
val parents1 =
if ((parents.length > 1) &&
(parents.head.symbol eq definitions.ObjectClass)) parents.tail;
(parents.head.typeSymbol eq definitions.ObjectClass)) parents.tail;
else parents;
parents1.mkXML(Text(""), <code> with </code>, Text(""))(link);
case _ =>
link(decode(tpe.symbol))
link(decode(tpe.typeSymbol))
}
}
@ -248,7 +249,7 @@ trait ModelToXML extends ModelExtractor {
def attrFor(attr: AnnotationInfo): Node = {
val buf = new StringBuilder
val AnnotationInfo(tpe, args, nvPairs) = attr
val name = link(decode(tpe.symbol))
val name = link(decode(tpe.typeSymbol))
if (!args.isEmpty)
buf.append(args.mkString("(", ",", ")"))
if (!nvPairs.isEmpty)

View File

@ -1,5 +1,5 @@
/* NSC -- new Scala compiler
* Copyright 2005-2006 LAMP/EPFL
* Copyright 2005-2007 LAMP/EPFL
* @author Burak Emir
*/
// $Id$
@ -8,7 +8,10 @@ package scala.tools.nsc.matching
import scala.tools.nsc.util.Position
/** contains many helper methods that build trees...some of these currently unused, since were for regexp matching
/** contains many helper methods that build trees...some of these currently
* unused, since were for regexp matching.
*
* @author Burak Emir
*/
trait CodeFactory {
self: transform.ExplicitOuter =>
@ -79,32 +82,32 @@ trait CodeFactory {
var i = condition.length - 1
while (i >= 0) {
result = If(condition(i), body(i), result)
i = i - 1
i -= 1
}
result
}
final def renamingBind(defaultv: Set[Symbol], scrut: Symbol, ndefault: Tree) = {
if(!defaultv.isEmpty) {
var dv:List[Symbol] = Nil
var to:List[Symbol] = Nil
if (!defaultv.isEmpty) {
var dv: List[Symbol] = Nil
var to: List[Symbol] = Nil
val it = defaultv.elements; while(it.hasNext) {
dv = it.next :: dv
to = scrut :: to
}
val tss = new TreeSymSubstituter(dv, to)
tss.traverse( ndefault )
tss.traverse(ndefault)
}
}
final def emptynessCheck(vsym: Symbol) = {
if(vsym.tpe.symbol == definitions.SomeClass) // is Some[_]
if (vsym.tpe.typeSymbol == definitions.SomeClass) // is Some[_]
Literal(Constant(true))
else // is Option[_]
Not(Select(Ident(vsym), nme.isEmpty))
}
final def makeIf(cond:Tree, thenp:Tree, elsep:Tree) = cond match {
final def makeIf(cond: Tree, thenp: Tree, elsep: Tree) = cond match {
case Literal(Constant(true)) => thenp
case Literal(Constant(false)) => elsep
case _ => If(cond, thenp, elsep)
@ -142,7 +145,7 @@ trait CodeFactory {
}
/** for tree of sequence type, returns tree that drops first i elements */
final def seqDrop(sel:Tree, i: Int) = if(i == 0) sel else
final def seqDrop(sel:Tree, i: Int) = if (i == 0) sel else
Apply(Select(Select(sel, "toList"), "drop"),
List(Literal(Constant(i))))
@ -283,31 +286,34 @@ trait CodeFactory {
var nsubstituted = 0
var nstatic = 0
final def squeezedBlock(vds:List[Tree], exp:Tree)(implicit theOwner: Symbol): Tree =
if(settings_squeeze)
final def squeezedBlock(vds: List[Tree], exp: Tree)(implicit theOwner: Symbol): Tree =
if (settings_squeeze)
squeezedBlock1(vds, exp)
else
Block(vds,exp)
final def squeezedBlock1(vds:List[Tree], exp:Tree)(implicit theOwner: Symbol): Tree = {
final def squeezedBlock1(vds: List[Tree], exp: Tree)(implicit theOwner: Symbol): Tree = {
val tpe = exp.tpe
class RefTraverser(sym:Symbol) extends Traverser {
class RefTraverser(sym: Symbol) extends Traverser {
var nref = 0
var nsafeRef = 0
override def traverse(tree: Tree) = tree match {
case t:Ident if t.symbol == sym =>
nref = nref + 1
nref += 1
if(sym.owner == currentOwner) { // oldOwner should match currentOwner
nsafeRef = nsafeRef + 1
nsafeRef += 1
} /*else if(nref == 1) {
Console.println("sym owner: "+sym.owner+" but currentOwner = "+currentOwner)
}*/
case t if nref > 1 => // abort, no story to tell
case t if nref > 1 =>
// abort, no story to tell
case t =>
super.traverse(t)
}
}
case t => super . traverse (t)
}
}
class Subst(sym:Symbol,rhs:Tree) extends Transformer {
class Subst(sym: Symbol, rhs: Tree) extends Transformer {
var stop = false
override def transform(tree: Tree) = tree match {
case t:Ident if t.symbol == sym =>
@ -316,12 +322,12 @@ trait CodeFactory {
case t if stop =>
t
case t =>
super . transform (t)
super.transform(t)
}
}
vds match {
case Nil => exp
case Nil =>
exp
case (vd:ValDef) :: rest =>
// recurse
val exp1 = squeezedBlock(rest, exp)
@ -335,8 +341,8 @@ trait CodeFactory {
nremoved = nremoved + 1
exp1
case 1 if rt.nsafeRef == 1 =>
nsubstituted = nsubstituted + 1
new Subst(sym, vd.rhs).transform( exp1 )
nsubstituted += 1
new Subst(sym, vd.rhs).transform(exp1)
case _ =>
exp1 match {
case Block(vds2, exp2) => Block(vd::vds2, exp2)

View File

@ -95,12 +95,12 @@ trait ParallelMatching {
if((column.length > 1) && isFlatCases(column)) {
if(settings_debug) {
Console.println("flat cases!"+column)
Console.println(scrutinee.tpe.symbol.children)
Console.println(scrutinee.tpe.typeSymbol.children)
Console.println(scrutinee.tpe.member(nme.tag))
Console.println(column.map { x => x.tpe.symbol.tag })
Console.println(column.map { x => x.tpe.typeSymbol.tag })
}
return new MixCases(scrutinee, column, rest)
// if(scrutinee.tpe.symbol.hasFlag(symtab.Flags.SEALED)) new MixCasesSealed(scrutinee, column, rest)
// if(scrutinee.tpe.typeSymbol.hasFlag(symtab.Flags.SEALED)) new MixCasesSealed(scrutinee, column, rest)
// else new MixCases(scrutinee, column, rest)
}
*/
@ -408,7 +408,7 @@ trait ParallelMatching {
private val patternType = column.head match {
case p @ (_:Ident | _:Select) =>
singleType(p.symbol.tpe.prefix, p.symbol) //ConstantType(p.tpe.singleton)
//case p@Apply(_,_) if !p.tpe.symbol.hasFlag(symtab.Flags.CASE) => ConstantType(new NamedConstant(p))
//case p@Apply(_,_) if !p.tpe.typeSymbol.hasFlag(symtab.Flags.CASE) => ConstantType(new NamedConstant(p))
case _ => column.head.tpe
}
private val isCaseHead = patternType.typeSymbol.hasFlag(symtab.Flags.CASE)
@ -517,7 +517,7 @@ trait ParallelMatching {
// succeeding => transition to translate(subsumed) (taking into account more specific)
val nmatrix = {
//Console.println("casted:"+casted)
//Console.println("casted.case:"+casted.tpe.symbol.hasFlag(symtab.Flags.CASE))
//Console.println("casted.case:"+casted.tpe.typeSymbol.hasFlag(symtab.Flags.CASE))
var ntemps = if(casted.tpe.typeSymbol.hasFlag(symtab.Flags.CASE)) casted.caseFieldAccessors map {
meth =>
val ctemp = newVar(scrutinee.pos, casted.tpe.memberType(meth).resultType)
@ -647,7 +647,7 @@ trait ParallelMatching {
case mc: MixCases =>
val (branches, defaultV, default) = mc.getTransition // tag body pairs
if(settings_debug) {
if (settings_debug) {
Console.println("[[mix cases transition: branches \n"+(branches.mkString("","\n","")))
Console.println("defaults:"+defaultV)
Console.println(default)
@ -807,7 +807,7 @@ object Rep {
pats = (if (tpt.tpe <:< temp(j).tpe) p else typat)::pats
case o @ Ident(n) =>
if(n != nme.WILDCARD) {
if (n != nme.WILDCARD) {
//Console.println("/'''''''''''' 1"+o.tpe)
//Console.println("/'''''''''''' 2"+o.symbol)
//Console.println("/'''''''''''' 3"+o.symbol.tpe)
@ -815,7 +815,7 @@ object Rep {
//Console.println("/'''''''''''' 5"+o.symbol.tpe.prefix.isStable)
val stpe =
if(o.tpe.symbol.isModule)
if (o.tpe.typeSymbol.isModule)
singleType(o.tpe.prefix, o.symbol)
else
singleType(NoPrefix, o.symbol)
@ -826,7 +826,7 @@ object Rep {
} else
pats = o::pats
case ua @ UnApply(Apply(fn,_),arg) =>
case ua @ UnApply(Apply(fn, _), arg) =>
fn.tpe match {
case MethodType(List(argtpe,_*),_) =>
pats = (if (temp(j).tpe <:< argtpe) ua else Typed(ua,TypeTree(argtpe)).setType(argtpe))::pats
@ -834,10 +834,12 @@ object Rep {
/** something too tricky is going on if the outer types don't match
*/
case o @ Apply(app, List()) if !o.tpe.symbol.hasFlag(symtab.Flags.CASE) =>
case o @ Apply(app, List()) if !o.tpe.typeSymbol.hasFlag(symtab.Flags.CASE) =>
//Console.println(o)
//val stpe = singleType(NoPrefix, o.symbol)
val stpe = if(o.tpe.symbol.isModule) singleType(o.tpe.prefix, o.symbol) else mkThisType(o.symbol)
val stpe =
if (o.tpe.typeSymbol.isModule) singleType(o.tpe.prefix, o.symbol)
else mkThisType(o.symbol)
val p = Ident(nme.WILDCARD) setType stpe
val q = Typed(p, TypeTree(stpe)) setType stpe
pats = q::pats
@ -846,11 +848,11 @@ object Rep {
pats = p :: pats
}
opats = opats.tail
j = j + 1
j += 1
}
pats = pats.reverse
//i = pats findIndexOf isAlternative
if(indexOfAlternative == -1)
if (indexOfAlternative == -1)
List(Row(pats,subst,g,b))
else {
val prefix = pats.take( indexOfAlternative )
@ -859,7 +861,7 @@ object Rep {
alts map { p => Row(prefix ::: p :: suffix, subst, g, b) }
}
}
if(unchanged) {
if (unchanged) {
val ri = RepImpl(temp,row).init
//Console.println("ri = "+ri)
ri
@ -882,7 +884,7 @@ object Rep {
//Console.println("sym! "+sym+" mutable? "+sym.hasFlag(symtab.Flags.MUTABLE)+" captured? "+sym.hasFlag(symtab.Flags.CAPTURED))
if (sym.hasFlag(symtab.Flags.MUTABLE) && // indicates that have not yet checked exhaustivity
!sym.hasFlag(symtab.Flags.CAPTURED) && // indicates @unchecked
sym.tpe.symbol.hasFlag(symtab.Flags.SEALED)) {
sym.tpe.typeSymbol.hasFlag(symtab.Flags.SEALED)) {
sym.resetFlag(symtab.Flags.MUTABLE)
sealedCols = i::sealedCols
@ -893,7 +895,7 @@ object Rep {
val z = candidates(x)
if(x.hasFlag(symtab.Flags.ABSTRACT)) z else z + x
}
val cases = candidates(sym.tpe.symbol)
val cases = candidates(sym.tpe.typeSymbol)
sealedComb = cases::sealedComb
}
}
@ -926,7 +928,7 @@ object Rep {
singleType(sym.tpe.prefix, sym.linkedModuleOfClass) // e.g. None, Nil
} else sym.tpe
//Console.print("covers: sym="+sym+" symtpe="+symtpe+" p="+p+", p.tpe="+p.tpe+" ?")
(p.tpe.symbol == sym) || (symtpe <:< p.tpe) ||
(p.tpe.typeSymbol == sym) || (symtpe <:< p.tpe) ||
/* outer, see scala.util.parsing.combinator.lexical.Scanner */
(p.tpe.prefix.memberType(sym) <:< p.tpe)
}
@ -964,7 +966,8 @@ object Rep {
//def setParent(mr:MixTypes): this.type = { mixtureParent = mr; this }
final def applyRule: RuleApplication = row match {
case Nil => ErrorRule
case Nil =>
ErrorRule
case Row(pats,subst,g,b)::xs =>
if(pats forall isDefaultPattern) {
val subst1 = pats.zip(temp) flatMap {
@ -1004,10 +1007,10 @@ object Rep {
/** creates initial clause matrix
*/
final def initRep(selector:Tree, cases:List[Tree], checkExhaustive: Boolean)(implicit theOwner: Symbol) = {
final def initRep(selector: Tree, cases: List[Tree], checkExhaustive: Boolean)(implicit theOwner: Symbol) = {
val root = newVar(selector.pos, selector.tpe)
// communicate whether exhaustiveness-checking is enabled via some flag
if(!checkExhaustive)
if (!checkExhaustive)
root.setFlag(symtab.Flags.CAPTURED)
val row = cases map { case CaseDef(pat,g,b) => Row(List(pat), Nil, g, b) }
Rep(List(root), row)
@ -1031,9 +1034,9 @@ object Rep {
* @param x a pattern
* @return vs variables bound, p pattern proper
*/
final def strip(x:Tree): (Set[Symbol], Tree) = x match {
case b @ Bind(_,pat) => val (vs,p) = strip(pat); (vs + b.symbol, p)
case z => (emptySymbolSet,z)
final def strip(x: Tree): (Set[Symbol], Tree) = x match {
case b @ Bind(_,pat) => val (vs, p) = strip(pat); (vs + b.symbol, p)
case z => (emptySymbolSet, z)
}
final def strip1(x:Tree): Set[Symbol] = x match { // same as strip(x)._1
@ -1054,25 +1057,25 @@ object Rep {
final def newVar(pos: Position, name: Name, tpe: Type)(implicit theOwner: Symbol): Symbol = {
if(tpe eq null) assert(tpe ne null, "newVar("+name+", null)")
val sym = theOwner.newVariable(pos, name) // careful: pos has special meaning
sym.setFlag(symtab.Flags.TRANS_FLAG)
sym.setInfo(tpe)
sym setFlag symtab.Flags.TRANS_FLAG
sym setInfo tpe
sym
}
final def newVar(pos: Position, tpe: Type)(implicit theOwner: Symbol): Symbol =
newVar(pos, cunit.fresh.newName("temp"), tpe).setFlag(symtab.Flags.SYNTHETIC)
newVar(pos, cunit.fresh.newName("temp"), tpe) setFlag symtab.Flags.SYNTHETIC
/** returns the condition in "if(cond) k1 else k2"
*/
final def condition(tpe: Type, scrut: Symbol): Tree = {
val res = condition1(tpe, scrut)
if(true && settings_debug)
if (settings_debug)
Console.println("condition, tpe = "+tpe+", scrut.tpe = "+scrut.tpe+", res = "+res)
res
}
final def condition1(tpe: Type, scrut: Symbol): Tree = {
assert (scrut ne NoSymbol)
condition(tpe, Ident(scrut) . setType (scrut.tpe) . setSymbol (scrut))
assert(scrut ne NoSymbol)
condition(tpe, Ident(scrut) setType scrut.tpe setSymbol scrut)
}
final def condition(tpe: Type, scrutineeTree: Tree): Tree = {
@ -1081,23 +1084,23 @@ object Rep {
//Console.println("tpe = "+tpe+" prefix="+tpe.prefix)
//Console.println("singletontype?"+tpe.isInstanceOf[SingletonType])
//Console.println("constanttype? "+tpe.isInstanceOf[ConstantType])
//Console.println("value "+tpe.symbol.isValue)
//Console.println("module "+tpe.symbol.isModule)
//Console.println("value "+tpe.typeSymbol.isValue)
//Console.println("module "+tpe.typeSymbol.isModule)
if (tpe.isInstanceOf[SingletonType] && !tpe.isInstanceOf[ConstantType]) {
if(tpe.symbol.isModule) {// object
if (tpe.typeSymbol.isModule) {// object
if (scrutineeTree.tpe <:< definitions.AnyRefClass.tpe)
Eq(gen.mkAttributedRef(tpe.symbol), scrutineeTree) // object
Eq(gen.mkAttributedRef(tpe.typeSymbol), scrutineeTree) // object
else
Equals(gen.mkAttributedRef(tpe.symbol), scrutineeTree) // object
Equals(gen.mkAttributedRef(tpe.typeSymbol), scrutineeTree) // object
} else {
//Console.print("111 ??")
//Console.println("tpe stable "+tpe.isStable)
//Console.println("tpe prefix stable "+tpe.prefix.isStable)
//val x = Equals(Apply(gen.mkAttributedRef(tpe.symbol), List()), scrutineeTree)
//val x = Equals(Apply(gen.mkAttributedRef(tpe.typeSymbol), List()), scrutineeTree)
val x =
if(tpe.prefix ne NoPrefix) gen.mkIsInstanceOf(scrutineeTree, tpe)
else Equals(gen.mkAttributedRef(tpe.symbol), scrutineeTree)
else Equals(gen.mkAttributedRef(tpe.typeSymbol), scrutineeTree)
//Console.println(" = "+x)
typed { x }
}
@ -1111,51 +1114,54 @@ object Rep {
Eq(scrutineeTree, Literal(value)) // constant
else
Equals(scrutineeTree, Literal(value)) // constant
} else if(scrutineeTree.tpe <:< tpe && tpe <:< definitions.AnyRefClass.tpe) {
} else if (scrutineeTree.tpe <:< tpe && tpe <:< definitions.AnyRefClass.tpe) {
//if(scrutineeTree.symbol.hasFlag(symtab.Flags.SYNTHETIC)) Literal(Constant(true)) else
NotNull(scrutineeTree)
} else if(tpe.prefix.symbol.isTerm && tpe.symbol.linkedModuleOfClass != NoSymbol) { // object
} else if(tpe.prefix.typeSymbol.isTerm && tpe.typeSymbol.linkedModuleOfClass != NoSymbol) { // object
//Console.println("iT"+tpe.prefix.symbol.isTerm)
//Console.println("lmoc"+tpe.symbol.linkedModuleOfClass)
Eq(gen.mkAttributedRef(tpe.prefix, tpe.symbol.linkedModuleOfClass), scrutineeTree)
//Console.println("lmoc"+tpe.typeSymbol.linkedModuleOfClass)
Eq(gen.mkAttributedRef(tpe.prefix, tpe.typeSymbol.linkedModuleOfClass), scrutineeTree)
} else
//Console.println(tpe.prefix.symbol.isTerm)
//Console.println(tpe.symbol)
//Console.println(tpe.symbol.linkedModuleOfClass)
//Console.println(tpe.typeSymbol)
//Console.println(tpe.typeSymbol.linkedModuleOfClass)
gen.mkIsInstanceOf(scrutineeTree, tpe)
}
final def needsOuterTest(tpe2test:Type, scrutinee:Type) = tpe2test.normalize match {
final def needsOuterTest(tpe2test: Type, scrutinee: Type) = tpe2test.normalize match {
case TypeRef(prefix,_,_) =>
prefix.symbol.isTerm &&
!prefix.symbol.isPackage &&
outerAlwaysEqual(tpe2test,scrutinee) == Some(false)
case _ => false
prefix.typeSymbol.isTerm &&
!prefix.typeSymbol.isPackage &&
outerAlwaysEqual(tpe2test, scrutinee) == Some(false)
case _ =>
false
}
/** returns a result if both are TypeRefs, returns Some(true) if left and right are statically known to have
* the same outer, i.e. if their prefixes are the same
*/
final def outerAlwaysEqual(left: Type, right: Type): Option[Boolean] = (left.normalize,right.normalize) match {
case (TypeRef(lprefix, _,_), TypeRef(rprefix,_,_)) =>
if(!(lprefix =:= rprefix)) {
final def outerAlwaysEqual(left: Type, right: Type): Option[Boolean] =
(left.normalize, right.normalize) match {
case (TypeRef(lprefix, _, _), TypeRef(rprefix, _, _)) =>
//if(!(lprefix =:= rprefix)) {
//DEBUG("DEBUG(outerAlwaysEqual) Some(f) for"+(left,right))
}
//}
Some(lprefix =:= rprefix)
case _ => None
case _ =>
None
}
/** adds a test comparing the dynamic outer to the static outer */
final def addOuterCondition(cond:Tree, tpe2test: Type, scrutinee: Tree, handleOuter: Tree=>Tree) = {
val TypeRef(prefix,_,_) = tpe2test
var theRef = gen.mkAttributedRef(prefix.prefix, prefix.symbol)
var theRef = gen.mkAttributedRef(prefix.prefix, prefix.typeSymbol)
// needs explicitouter treatment
theRef = handleOuter(theRef)
val outerAcc = outerAccessor(tpe2test.symbol)
val outerAcc = outerAccessor(tpe2test.typeSymbol)
if (outerAcc == NoSymbol) {
if (settings_debug) cunit.warning(scrutinee.pos, "no outer acc for "+tpe2test.symbol)
if (settings_debug) cunit.warning(scrutinee.pos, "no outer acc for "+tpe2test.typeSymbol)
cond
} else
And(cond,

View File

@ -60,7 +60,7 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
this.doCheckExhaustive = doCheckExhaustive
this.selector = selector
this.handleOuter = handleOuter
if(settings_debug) {
if (settings_debug) {
Console.println("****")
Console.println("**** initalize, selector = "+selector+" selector.tpe = "+selector.tpe)
Console.println("**** doCheckExhaustive == "+doCheckExhaustive)
@ -239,7 +239,9 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
//Console.println("isImplemented? "+x)
x match {
case app @ Apply(fn,xs) =>
if(!app.tpe.symbol.hasFlag(symtab.Flags.CASE) /*|| (fn.symbol ne null)*/) CantHandleApply else {
if(!app.tpe.typeSymbol.hasFlag(symtab.Flags.CASE) /*|| (fn.symbol ne null)*/)
CantHandleApply
else {
/*if(!app.tpe.symbol.hasFlag(symtab.Flags.CASE)) {
Console.print("what is this?"+x)
if(fn.symbol eq null) {
@ -349,12 +351,12 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
//Console.println("tree.tpe "+tree.tpe);
//Console.println("tree.getClass() "+tree.getClass());
val t = tree match {
case Bind(name, Typed(Ident( nme.WILDCARD ), tpe)) => // x@_:Type
case Bind(name, Typed(Ident(nme.WILDCARD), tpe)) => // x@_:Type
// @note: safest! typer does not always use tpe.tpe, e.g. in the case of refinement type tests
val tpe2test = tree.symbol.tpe
// @note: if (isSubType(header.tpe, tpe2test)) then this will be translated to isNull test
val node = pConstrPat(tree.pos, tpe2test)
env.newBoundVar( tree.symbol, tpe2test, typed(Ident( node.casted )));
env.newBoundVar(tree.symbol, tpe2test, typed(Ident(node.casted)));
node
case Bind(name, Ident(nme.WILDCARD)) => // x @ _
@ -387,7 +389,7 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
if(isRightIgnoring(av)) {
//Console.println(av.toString()+" IS RIGHTIGNORING");
val castedRest = ts.last match {
case b:Bind => b.symbol;
case b:Bind => b.symbol
case _ => null
}
pRightIgnoringSequencePat(tree.pos, tree.tpe, castedRest, ts.length-1);
@ -516,13 +518,13 @@ trait PatternMatchers { self: transform.ExplicitOuter with PatternNodes with Par
} else {
//Console.println("NOT FIRSTPOS");
//Console.println("newHeader :: ");
if(!casted.tpe.symbol.hasFlag(Flags.CASE)) {
if (!casted.tpe.typeSymbol.hasFlag(Flags.CASE)) {
//Console.println("NOT CASE");
//Console.println("getProductArgs? "+defs.getProductArgs(casted.tpe));
defs.getProductArgs(casted.tpe) match {
case Some(targs) =>
val accSym = defs.productProj(casted.tpe.symbol, index+1)
val accSym = defs.productProj(casted.tpe.typeSymbol, index+1)
val accTree = typed(Apply(Select(ident, accSym), List())) // nsc !
return pHeader(pos, accTree.tpe, accTree)
case None =>
@ -541,8 +543,8 @@ print()
//Console.println("CASE");
val caseAccs = casted.tpe.symbol.caseFieldAccessors;
if (caseAccs.length <= index) Console.println("selecting " + index + " in case fields of " + casted.tpe.symbol + "=" + casted.tpe.symbol.caseFieldAccessors);//debug
val caseAccs = casted.tpe.typeSymbol.caseFieldAccessors;
if (caseAccs.length <= index) Console.println("selecting " + index + " in case fields of " + casted.tpe.typeSymbol + "=" + casted.tpe.typeSymbol.caseFieldAccessors);//debug
val ts = caseAccs(index);
val accTree = typed(Apply(Select(ident, ts), List()))
val accType = accTree.tpe
@ -624,8 +626,8 @@ print()
/* first try at exhaust improvement
selectorMap.update((casted, curHeader.selector.symbol),
selectorMap.get(casted, curHeader.selector.symbol) match {
case Some(xs) => pat.tpe.symbol::xs
case _ => pat.tpe.symbol::Nil
case Some(xs) => pat.tpe.typeSymbol::xs
case _ => pat.tpe.typeSymbol::Nil
})
*/
if (bodycond ne null) target.and = bodycond(target.and) // restores body with the guards
@ -709,7 +711,7 @@ print()
protected def nCaseComponents(tree: Tree): int = {
tree match {
case Apply(fn, _) =>
val tpe = tree.tpe.symbol.primaryConstructor.tpe
val tpe = tree.tpe.typeSymbol.primaryConstructor.tpe
//Console.println("~~~ " + tree.type() + ", " + tree.type().symbol.primaryConstructor());
tpe match {
// I'm not sure if this is a good idea, but obviously, currently all case classes
@ -1070,15 +1072,15 @@ print()
while (node ne null)
node match {
case ConstrPat(casted) =>
cases = insertNode(node.tpe.symbol.tag, node, cases)
cases = insertNode(node.tpe.typeSymbol.tag, node, cases)
node = node.or
case DefaultPat() =>
defaultCase = node
node = node.or
case VariablePat(tree) if node.tpe.symbol.hasFlag(Flags.CASE) =>
cases = insertNode(node.tpe.symbol.tag, node, cases)
case VariablePat(tree) if node.tpe.typeSymbol hasFlag Flags.CASE =>
cases = insertNode(node.tpe.typeSymbol.tag, node, cases)
node = node.or
case _ =>
@ -1146,7 +1148,7 @@ print()
case DefaultPat() =>
return toTree(node.and);
case UnapplyPat(casted, Apply(fn1, appargs)) if casted.tpe.symbol == defs.BooleanClass => // special case
case UnapplyPat(casted, Apply(fn1, appargs)) if casted.tpe.typeSymbol == defs.BooleanClass => // special case
var useSelector = selector
val checkType = fn1.tpe match {
case MethodType(List(argtpe,_*),_) =>
@ -1218,7 +1220,7 @@ print()
// needs explicitouter treatment
theRef = handleOuter(theRef)
val outerAcc = outerAccessor(casted.tpe.symbol)
val outerAcc = outerAccessor(casted.tpe.typeSymbol)
if(outerAcc != NoSymbol) { // some guys don't have outers
cond = And(cond,
@ -1288,13 +1290,13 @@ print()
Literal(Constant(true))
val treeAsSeq =
if(!isSubType(selector.tpe,ntpe))
if (!isSubType(selector.tpe,ntpe))
typed(gen.mkAsInstanceOf(selector.duplicate, ntpe, true))
else
selector.duplicate
val cond =
if(minlen == 0) tpetest
if (minlen == 0) tpetest
else And(tpetest, seqLongerThan(treeAsSeq, ntpe, minlen))
var bindings =
@ -1320,11 +1322,11 @@ print()
case VariablePat(tree) =>
// objects are compared by eq, not ==
val cmp = if(tree.tpe.symbol.isModuleClass && selector.tpe <:< defs.AnyRefClass.tpe)
val cmp = if (tree.tpe.typeSymbol.isModuleClass && selector.tpe <:< defs.AnyRefClass.tpe)
Eq(selector.duplicate, tree)
else
Equals(selector.duplicate, tree)
return myIf( cmp,
return myIf(cmp,
toTree(node.and),
toTree(node.or, selector.duplicate));
@ -1333,7 +1335,7 @@ print()
toTree(node.and),
toTree(node.or, selector.duplicate));
case _ =>
scala.Predef.error("cannot handle pattern:"+node);
scala.Predef.error("cannot handle pattern:"+node)
}
}
}

View File

@ -57,8 +57,15 @@ trait Scanners extends Parsers with Tokens {
token(in1) match {
case Success(tok, in2) => Triple(tok, in1, in2)
case ns: NoSuccess => Triple(errorToken(ns.msg), ns.next, skip(ns.next))
case Failure(_, in2) => error("internal error")
case Error(_, in2) => error("internal error")
}
case ns: NoSuccess => Triple(errorToken(ns.msg), ns.next, skip(ns.next))
case ns: NoSuccess =>
Triple(errorToken(ns.msg), ns.next, skip(ns.next))
case Failure(_, in1) =>
error("internal error")
case Error(_, in1) =>
error("internal error")
}
private def skip(in: Reader[Char]) = if (in.atEnd) in else in.rest