summaryrefslogtreecommitdiff
path: root/sources/scala/tools/nsc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2005-10-17 21:49:56 +0000
committerMartin Odersky <odersky@gmail.com>2005-10-17 21:49:56 +0000
commit15956fc33e4bdc8eb760fdaeaf88744065177387 (patch)
tree1a3f0ae68865cdc8208092d3cc22dae531043480 /sources/scala/tools/nsc
parentdb20991e477bec6e2f0d752a6aae943aefde88bb (diff)
downloadscala-15956fc33e4bdc8eb760fdaeaf88744065177387.tar.gz
scala-15956fc33e4bdc8eb760fdaeaf88744065177387.tar.bz2
scala-15956fc33e4bdc8eb760fdaeaf88744065177387.zip
*** empty log message ***
Diffstat (limited to 'sources/scala/tools/nsc')
-rwxr-xr-xsources/scala/tools/nsc/CompilerRun.scala1
-rwxr-xr-xsources/scala/tools/nsc/Global.scala1
-rwxr-xr-xsources/scala/tools/nsc/ast/parser/Parsers.scala2
-rw-r--r--sources/scala/tools/nsc/ast/parser/Tokens.scala2
-rwxr-xr-xsources/scala/tools/nsc/symtab/Symbols.scala27
-rwxr-xr-xsources/scala/tools/nsc/symtab/Types.scala53
-rwxr-xr-xsources/scala/tools/nsc/transform/Erasure.scala6
-rwxr-xr-xsources/scala/tools/nsc/transform/ExplicitOuter.scala1
-rwxr-xr-xsources/scala/tools/nsc/transform/Flatten.scala9
-rwxr-xr-xsources/scala/tools/nsc/transform/LambdaLift.scala22
-rwxr-xr-xsources/scala/tools/nsc/transform/Mixin.scala8
-rwxr-xr-xsources/scala/tools/nsc/typechecker/RefChecks.scala3
-rwxr-xr-xsources/scala/tools/nsc/typechecker/Typers.scala14
-rwxr-xr-xsources/scala/tools/nsc/util/HashSet.scala26
-rw-r--r--sources/scala/tools/nsc/util/Statistics.scala4
15 files changed, 68 insertions, 111 deletions
diff --git a/sources/scala/tools/nsc/CompilerRun.scala b/sources/scala/tools/nsc/CompilerRun.scala
index a361a1ff28..d41371f041 100755
--- a/sources/scala/tools/nsc/CompilerRun.scala
+++ b/sources/scala/tools/nsc/CompilerRun.scala
@@ -13,6 +13,7 @@ class CompilerRun {
def refchecksPhase: Phase = NoPhase;
def erasurePhase: Phase = NoPhase;
def flattenPhase: Phase = NoPhase;
+ def mixinPhase: Phase = NoPhase;
def phaseNamed(name: String): Phase = NoPhase;
}
diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala
index 58666f0f5f..afc69264ce 100755
--- a/sources/scala/tools/nsc/Global.scala
+++ b/sources/scala/tools/nsc/Global.scala
@@ -299,6 +299,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
override val refchecksPhase = phaseNamed("refchecks");
override val erasurePhase = phaseNamed("erasure");
override val flattenPhase = phaseNamed("flatten");
+ override val mixinPhase = phaseNamed("mixin");
private var unitbuf = new ListBuffer[CompilationUnit];
private var fileset = new HashSet[AbstractFile];
diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala
index d2155f5e39..c9ef20a225 100755
--- a/sources/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala
@@ -180,7 +180,7 @@ import Tokens._;
params
case Ident(_) | Typed(Ident(_), _) =>
List(convertToParam(t));
- case Literal(c) if c.tag == UnitTag => //todo: check with Literal(Constant())
+ case Literal(c) if c.tag == UnitTag =>
Nil
case _ =>
syntaxError(t.pos, "malformed formal parameter list", false);
diff --git a/sources/scala/tools/nsc/ast/parser/Tokens.scala b/sources/scala/tools/nsc/ast/parser/Tokens.scala
index 85340fa84b..cd6a4ded54 100644
--- a/sources/scala/tools/nsc/ast/parser/Tokens.scala
+++ b/sources/scala/tools/nsc/ast/parser/Tokens.scala
@@ -81,7 +81,7 @@ object Tokens {
final val SUPERTYPE = 71;
final val HASH = 72;
final val AT = 73;
- final val VIEWBOUND = 74; //todo: elim?
+ final val VIEWBOUND = 74;
/** parenthesis */
final val LPAREN = 90;
diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala
index 44b02bc51c..92887ac6b6 100755
--- a/sources/scala/tools/nsc/symtab/Symbols.scala
+++ b/sources/scala/tools/nsc/symtab/Symbols.scala
@@ -427,12 +427,12 @@ import Flags._;
def filter(cond: Symbol => boolean): Symbol =
if (hasFlag(OVERLOADED)) {
//assert(info.isInstanceOf[OverloadedType], "" + this + ":" + info);//DEBUG
- val alts = alternatives;
- val alts1 = alts filter cond;
- if (alts1 eq alts) this
- else if (alts1.isEmpty) NoSymbol
- else if (alts1.tail.isEmpty) alts1.head
- else owner.newOverloaded(info.prefix, alts1)
+ val alts = alternatives;
+ val alts1 = alts filter cond;
+ if (alts1 eq alts) this
+ else if (alts1.isEmpty) NoSymbol
+ else if (alts1.tail.isEmpty) alts1.head
+ else owner.newOverloaded(info.prefix, alts1)
} else if (cond(this)) this
else NoSymbol;
@@ -519,7 +519,7 @@ import Flags._;
*/
final def linkedModule: Symbol =
if (owner.isPackageClass)
- owner.info.decl(name.toTermName).suchThat(
+ owner.info.decl(name.toTermName).suchThat(
sym => (sym hasFlag MODULE) && (sym.rawInfo ne NoType));
else NoSymbol;
@@ -536,9 +536,10 @@ import Flags._;
final def toInterface: Symbol =
if (isImplClass) {
- val iface = tpe.parents.last.symbol;
- assert(nme.implClassName(iface.name) == name, this);
- iface
+ assert(!tpe.parents.isEmpty, this);
+ val iface = tpe.parents.last.symbol;
+ assert(nme.implClassName(iface.name) == name, this);
+ iface
} else this;
/** The module corresponding to this module class (note that this
@@ -569,8 +570,8 @@ import Flags._;
var sym: Symbol = NoSymbol;
while (!bcs.isEmpty && sym == NoSymbol) {
if (!bcs.head.isImplClass)
- sym = overriddenSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED));
- bcs = bcs.tail
+ sym = overriddenSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED));
+ bcs = bcs.tail
}
sym
}
@@ -590,7 +591,7 @@ import Flags._;
if (isTerm && (this hasFlag PRIVATE)) {
setFlag(notPRIVATE);
if (!hasFlag(DEFERRED)) setFlag(lateFINAL);
- expandName(base)
+ expandName(base)
}
/** change name by appending $$<fully-qualified-name-of-class `base'>
diff --git a/sources/scala/tools/nsc/symtab/Types.scala b/sources/scala/tools/nsc/symtab/Types.scala
index 4ed2563d6c..c7a5c47c8f 100755
--- a/sources/scala/tools/nsc/symtab/Types.scala
+++ b/sources/scala/tools/nsc/symtab/Types.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc.symtab;
import scala.tools.util.Position;
-import nsc.util.ListBuffer;
+import nsc.util.{ListBuffer, HashSet};
import Flags._;
/* A standard type pattern match:
@@ -1014,53 +1014,14 @@ import Flags._;
// Hash consing --------------------------------------------------------------
- private var size = 20000;
- private var used = 0;
- private var table = new Array[Type](size);
-
- var uniques = 0;
- var accesses = 0;
- var collisions = 0; //todo: use HashSet!
-
- private def findEntry(tp: Type): Type = {
- var h = tp.hashCode() % size;
- if (util.Statistics.enabled) accesses = accesses + 1;
- var entry = table(h);
- while (entry != null && entry != tp) {
- if (util.Statistics.enabled) collisions = collisions + 1;
- h = (h + 1) % size;
- entry = table(h)
- }
- entry
- }
+ private val uniques = new HashSet[AnyRef](20000);
- private def addEntry(tp: Type): unit = {
- if (used >= (size >> 2)) growTable;
- used = used + 1;
- var h = tp.hashCode() % size;
- while (table(h) != null) {
- h = (h + 1) % size
- }
- table(h) = tp
- }
+ def uniqueTypeCount = uniques.size; // for statistics
- private def growTable: unit = {
- val oldtable = table;
- size = size * 2;
- table = new Array[Type](size);
- var i = 0;
- while (i < oldtable.length) {
- val entry = oldtable(i);
- if (entry != null) addEntry(entry);
- i = i + 1
- }
- }
-
- private def unique[T <: Type](tp: T): T = {
- val tp1 = findEntry(tp);
+ private def unique[T <: AnyRef](tp: T): T = {
+ val tp1 = uniques.findEntry(tp);
if (tp1 == null) {
- if (util.Statistics.enabled) uniques = uniques + 1;
- addEntry(tp); tp
+ uniques.addEntry(tp); tp
} else {
tp1.asInstanceOf[T]
}
@@ -1152,7 +1113,7 @@ import Flags._;
if ((tparams1 eq tparams) && (result1 eq result)) tp
else PolyType(tparams1, result1.substSym(tparams, tparams1))
case OverloadedType(pre, alts) =>
- val pre1 = this(pre);
+ val pre1 = if (pre.isInstanceOf[ClassInfoType]) pre else this(pre);
if (pre1 eq pre) tp
else OverloadedType(pre1, alts)
case AntiPolyType(pre, args) =>
diff --git a/sources/scala/tools/nsc/transform/Erasure.scala b/sources/scala/tools/nsc/transform/Erasure.scala
index 188a3c8163..30c5ddb43b 100755
--- a/sources/scala/tools/nsc/transform/Erasure.scala
+++ b/sources/scala/tools/nsc/transform/Erasure.scala
@@ -211,12 +211,6 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
gen.cast(tree, pt)
}
- // todo: remove after removing ==, != from value classes
- private def corresponds(sym: Symbol, anyMember: Symbol): boolean =
- sym == anyMember ||
- sym != NoSymbol && isValueClass(sym.owner) && sym.name == anyMember.name && sym.tpe == anyMember.tpe;
-
-
/** Replace member references as follows:
* - `x == y' for `==' in class Any becomes `x equals y' with `equals' in class Object
* - `x != y' for `!=' in class Any becomes `!(x equals y)' with `equals' in class Object
diff --git a/sources/scala/tools/nsc/transform/ExplicitOuter.scala b/sources/scala/tools/nsc/transform/ExplicitOuter.scala
index 5796f1c6f6..ce81d75416 100755
--- a/sources/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/sources/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -145,6 +145,7 @@ abstract class ExplicitOuter extends InfoTransform {
* to super accessor symbols.
* //todo: not clear whether we need to this for all super calls symbols, or just
* protected ones (or all calls to protected from inner classes)?
+ * (controled by switch `needSuperAccessors')
*/
private val superAccessors = new HashMap[Triple[Symbol, Symbol, Name], Symbol];
diff --git a/sources/scala/tools/nsc/transform/Flatten.scala b/sources/scala/tools/nsc/transform/Flatten.scala
index 8b03000a4f..031f7a0fcd 100755
--- a/sources/scala/tools/nsc/transform/Flatten.scala
+++ b/sources/scala/tools/nsc/transform/Flatten.scala
@@ -97,14 +97,7 @@ abstract class Flatten extends InfoTransform {
case _ =>
tree
}
- tree1 setType flattened(tree1.tpe);
-/*
- if (sym != null && sym.isNestedClass && !(sym hasFlag LIFTED)) {
- liftClass(sym);//todo: remove
- if (sym.implClass != NoSymbol) liftClass(sym.implClass);
- }
-*/
- tree1
+ tree1 setType flattened(tree1.tpe)
}
/** Transform statements and add lifted definitions to them. */
diff --git a/sources/scala/tools/nsc/transform/LambdaLift.scala b/sources/scala/tools/nsc/transform/LambdaLift.scala
index 2cedb71a90..21f13e39c0 100755
--- a/sources/scala/tools/nsc/transform/LambdaLift.scala
+++ b/sources/scala/tools/nsc/transform/LambdaLift.scala
@@ -317,17 +317,21 @@ abstract class LambdaLift extends InfoTransform {
}
}
- override def transform(tree: Tree): Tree =
+ override def transform(tree: Tree): Tree = {
postTransform(super.transform(tree) setType lifted(tree.tpe));
-
- /** Transform statements and add lifted definitions to them. */
- override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
- val stats1 = super.transformStats(stats, exprOwner);
- if (currentOwner.isClass && !currentOwner.isPackageClass && liftedDefs(currentOwner).hasNext)
- stats1 ::: liftedDefs(currentOwner).toList
- else
- stats1
}
+ /** Transform statements and add lifted definitions to them. */
+ override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] =
+ for (val stat <- super.transformStats(stats, exprOwner)) yield {
+ stat match {
+ case ClassDef(mods, name, tparams, tpt, impl @ Template(parents, body))
+ if (liftedDefs(stat.symbol).hasNext) =>
+ copy.ClassDef(stat, mods, name, tparams, tpt,
+ copy.Template(impl, parents, body ::: liftedDefs(stat.symbol).toList))
+ case _ =>
+ stat
+ }
+ }
override def transformUnit(unit: CompilationUnit): unit = {
computeFreeVars;
diff --git a/sources/scala/tools/nsc/transform/Mixin.scala b/sources/scala/tools/nsc/transform/Mixin.scala
index 6fecdedcba..a0eccb0e64 100755
--- a/sources/scala/tools/nsc/transform/Mixin.scala
+++ b/sources/scala/tools/nsc/transform/Mixin.scala
@@ -25,7 +25,8 @@ abstract class Mixin extends InfoTransform {
private def isStatic(sym: Symbol) = isForwarded(sym) && (sym.hasFlag(PRIVATE) || sym.isConstructor);
- private def toInterface(tp: Type): Type = tp.symbol.toInterface.tpe;
+ private def toInterface(tp: Type): Type =
+ atPhase(currentRun.mixinPhase)(tp.symbol.toInterface).tpe;
private def rebindSuper(base: Symbol, member: Symbol, prevowner: Symbol): Symbol =
atPhase(currentRun.refchecksPhase) {
@@ -80,6 +81,7 @@ abstract class Mixin extends InfoTransform {
}
} else if ((member hasFlag (LIFTED | BRIDGE)) && !(member hasFlag PRIVATE)) {
member.expandName(clazz);
+ if (settings.debug.value) log("adding " + member + " to " + clazz);
addMember(clazz, member.cloneSymbol(clazz));
}
}
@@ -346,8 +348,8 @@ abstract class Mixin extends InfoTransform {
case Select(qual, name) if sym.owner.isImplClass && !isStatic(sym) =>
if (sym.isMethod) {
assert(sym hasFlag (LIFTED | BRIDGE), sym);
- val sym1 = enclInterface.info.decl(sym.name);
- assert(sym1 != NoSymbol, sym);
+ val sym1 = toInterface(qual.tpe).member(sym.name);
+ assert(sym1 != NoSymbol, "" + sym + " " + toInterface(qual.tpe));//debug
assert(!(sym1 hasFlag OVERLOADED), sym);//debug
tree setSymbol sym1
} else {
diff --git a/sources/scala/tools/nsc/typechecker/RefChecks.scala b/sources/scala/tools/nsc/typechecker/RefChecks.scala
index eb3ea846e8..9f3bb56d3c 100755
--- a/sources/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/sources/scala/tools/nsc/typechecker/RefChecks.scala
@@ -394,7 +394,7 @@ abstract class RefChecks extends InfoTransform {
for (val stat <- stats) {
index = index + 1;
stat match {
- case ClassDef(_, _, _, _, _) | DefDef(_, _, _, _, _, _) =>
+ case ClassDef(_, _, _, _, _) | DefDef(_, _, _, _, _, _) | ModuleDef(_, _, _) | ValDef(_, _, _, _) =>
assert(stat.symbol != NoSymbol, stat);//debug
if (stat.symbol.isLocal) {
currentLevel.scope.enter(newScopeEntry(stat.symbol, currentLevel.scope));
@@ -459,7 +459,6 @@ abstract class RefChecks extends InfoTransform {
case ValDef(_, _, _, _) =>
val tree1 = transform(tree); // important to do before forward reference check
- //todo: handle variables
if (tree.symbol.isLocal && index <= currentLevel.maxindex) {
if (settings.debug.value) System.out.println(currentLevel.refsym);
unit.error(currentLevel.refpos, "forward reference extends over definition of " + tree.symbol);
diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala
index 181dbba00d..0d0f5b0244 100755
--- a/sources/scala/tools/nsc/typechecker/Typers.scala
+++ b/sources/scala/tools/nsc/typechecker/Typers.scala
@@ -188,6 +188,7 @@ import collection.mutable.HashMap;
setError(tree)
}
}
+
override def apply(t: Type): Type = {
def checkNoEscape(sym: Symbol): unit = {
if (sym.hasFlag(PRIVATE)) {
@@ -197,7 +198,7 @@ import collection.mutable.HashMap;
if (o == sym.owner) badSymbol = sym
} else if (sym.owner.isTerm) {
val e = scope.lookupEntry(sym.name);
- if (e != null && e.sym == sym && e.owner == scope) badSymbol = e.sym
+ if (e != null && e.sym == sym && e.owner == scope && !e.sym.isTypeParameter) badSymbol = e.sym
}
}
if (badSymbol == NoSymbol)
@@ -544,6 +545,7 @@ import collection.mutable.HashMap;
val vdef = copy.ValDef(stat, mods | PRIVATE | LOCAL, nme.getterToLocal(name), tpe, rhs);
val value = vdef.symbol;
val getter = if ((mods & DEFERRED) != 0) value else value.getter(value.owner);
+ if (getter hasFlag OVERLOADED) System.out.println("overloaded getter: " + getter.alternatives + getter.alternatives.map(.tpe));//debug
assert(getter != NoSymbol, value);//debug
val getterDef: DefDef = {
val result = atPos(vdef.pos)(
@@ -666,15 +668,13 @@ import collection.mutable.HashMap;
val tparams1 = List.mapConserve(ddef.tparams)(typedAbsTypeDef);
val vparamss1 = List.mapConserve(ddef.vparamss)(vparams1 =>
List.mapConserve(vparams1)(typedValDef));
-/*
for (val vparams <- vparamss1; val vparam <- vparams) {
- checkNoEscaping.locals(paramScope, WildcardType, vparam.tpt); ()
+ checkNoEscaping.locals(context.scope, WildcardType, vparam.tpt); ()
}
-*/
var tpt1 =
-// checkNoEscaping.locals(context.scope, WildcardType,
+ checkNoEscaping.locals(context.scope, WildcardType,
checkNoEscaping.privates(meth,
- typedType(ddef.tpt));
+ typedType(ddef.tpt)));
checkNonCyclic(ddef.pos, tpt1.tpe, meth);
val rhs1 =
checkNoEscaping.locals(
@@ -894,7 +894,7 @@ import collection.mutable.HashMap;
case ErrorType =>
setError(tree)
case _ =>
- throw new Error("Matcherror at " + phase + " " + fun.tpe);//debug
+ errorTree(tree, "" + fun + " does not take parameters");
}
/** The qualifying class of a this or super with prefix `qual' */
diff --git a/sources/scala/tools/nsc/util/HashSet.scala b/sources/scala/tools/nsc/util/HashSet.scala
index 5751c49001..d74d7e9582 100755
--- a/sources/scala/tools/nsc/util/HashSet.scala
+++ b/sources/scala/tools/nsc/util/HashSet.scala
@@ -5,28 +5,30 @@
// $Id$
package scala.tools.nsc.util;
-class HashSet[T <: AnyRef](capacity: int) extends Set[T] {
+class HashSet[T <: AnyRef](initialCapacity: int) extends Set[T] {
- private var size = capacity;
+ private var capacity = initialCapacity;
private var used = 0;
- private var table = new Array[Object](size);
+ private var table = new Array[Object](capacity);
+
+ def size: int = used;
def findEntry(x: T): T = {
- var h = x.hashCode() % size;
+ var h = x.hashCode() % capacity;
var entry = table(h);
while (entry != null && entry != x) {
- h = (h + 1) % size;
+ h = (h + 1) % capacity;
entry = table(h)
}
entry.asInstanceOf[T]
}
def addEntry(x: T): unit = {
- if (used >= (size >> 2)) growTable;
+ if (used >= (capacity >> 2)) growTable;
used = used + 1;
- var h = x.hashCode() % size;
+ var h = x.hashCode() % capacity;
while (table(h) != null) {
- h = (h + 1) % size
+ h = (h + 1) % capacity
}
table(h) = x
}
@@ -34,8 +36,8 @@ class HashSet[T <: AnyRef](capacity: int) extends Set[T] {
def elements = new Iterator[T] {
private var i = 0;
def hasNext: boolean = {
- while (i < size && table(i) == null) i = i + 1;
- i < size
+ while (i < capacity && table(i) == null) i = i + 1;
+ i < capacity
}
def next: T =
if (hasNext) { i = i + 1; table(i - 1).asInstanceOf[T] }
@@ -44,8 +46,8 @@ class HashSet[T <: AnyRef](capacity: int) extends Set[T] {
private def growTable: unit = {
val oldtable = table;
- size = size * 2;
- table = new Array[Object](size);
+ capacity = capacity * 2;
+ table = new Array[Object](capacity);
var i = 0;
while (i < oldtable.length) {
val entry = oldtable(i);
diff --git a/sources/scala/tools/nsc/util/Statistics.scala b/sources/scala/tools/nsc/util/Statistics.scala
index 5033ee68af..2034b07541 100644
--- a/sources/scala/tools/nsc/util/Statistics.scala
+++ b/sources/scala/tools/nsc/util/Statistics.scala
@@ -24,9 +24,7 @@ abstract class Statistics {
inform("#applications: " + analyzer.appcnt);
inform("#implicits : " + analyzer.implcnt);
inform("ms implicits : " + analyzer.impltime);
- inform("#typecreates : " + accesses);
- inform("#uniquetypes : " + uniques);
- inform("#collisions : " + collisions);
+ inform("#uniquetypes : " + uniqueTypeCount);
inform("#symbols : " + symbolCount);
inform("#type symbols: " + typeSymbolCount);
inform("#class symbols: " + classSymbolCount);