summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-05-21 18:35:15 +0000
committerMartin Odersky <odersky@gmail.com>2003-05-21 18:35:15 +0000
commit703ab37f59911a301bf72e26979da6884874b59e (patch)
tree1ea0632c865023c3a5c5ae52e8de82adeab4c26f /sources
parentd62458f59a537908a42c4f650ef5973ba5b0b449 (diff)
downloadscala-703ab37f59911a301bf72e26979da6884874b59e.tar.gz
scala-703ab37f59911a301bf72e26979da6884874b59e.tar.bz2
scala-703ab37f59911a301bf72e26979da6884874b59e.zip
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/symtab/Symbol.java38
-rw-r--r--sources/scalac/typechecker/Analyzer.java16
2 files changed, 41 insertions, 13 deletions
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 4c2080fd40..c4f0c1a9c6 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -645,6 +645,11 @@ public abstract class Symbol implements Modifiers, Kinds {
return type();
}
+ /** Get this symbol of current class
+ */
+ public Symbol thisSym() { return this; }
+
+
/** A total ordering between symbols that refines the class
* inheritance graph (i.e. subclass.isLess(superclass) always holds).
*/
@@ -1085,23 +1090,29 @@ public class TypeSymbol extends Symbol {
assert closures.closure != BAD_CLOSURE : this;
closures.closure = BAD_CLOSURE; // to catch cycles.
// todo: why can't we do: inclClosure(SymSet.EMPTY, this) ?
- SymSet closureClassSet = inclClosureBases(SymSet.EMPTY, this);
+ SymSet closureClassSet = inclClosure(SymSet.EMPTY, type().parents());
Symbol[] closureClasses = new Symbol[closureClassSet.size() + 1];
closureClasses[0] = this;
closureClassSet.copyToArray(closureClasses, 1);
//System.out.println(ArrayApply.toString(closureClasses));//DEBUG
closures.closure = Symbol.type(closureClasses);
- //System.out.println(ArrayApply.toString(closures.closure));//DEBUG
+ //System.out.println("closure(" + this + ") = " + ArrayApply.toString(closures.closure));//DEBUG
adjustType(type());
//System.out.println("closure(" + this + ") at " + Global.instance.currentPhase.name() + " = " + ArrayApply.toString(closures.closure));//DEBUG
}
//where
- private SymSet inclClosureBases(SymSet set, Symbol c) {
- Type[] parents = c.type().parents();
- for (int i = 0; i < parents.length; i++) {
- set = inclClosure(set, parents[i].symbol());
+ private SymSet inclClosure(SymSet set, Type[] tps) {
+ for (int i = 0; i < tps.length; i++) {
+ Type tp = tps[i].unalias();
+ switch (tp) {
+ case CompoundType(Type[] parents, _):
+ set = inclClosure(set, parents);
+ break;
+ default:
+ set = inclClosure(set, tp.symbol());
+ }
}
return set;
}
@@ -1109,14 +1120,19 @@ public class TypeSymbol extends Symbol {
private SymSet inclClosure(SymSet set, Symbol c) {
Symbol c1 = c;
while (c1.kind == ALIAS) c1 = c1.info().symbol();
- return inclClosureBases(set.incl(c1), c1);
+ return inclClosure(set.incl(c1), c1.type().parents());
}
void adjustType(Type tp) {
Type tp1 = tp.unalias();
- int pos = closurePos(tp1.symbol());
- assert pos >= 0 : this + " " + tp1 + " " + tp1.symbol();
- closures.closure[pos] = tp1;
+ switch (tp) {
+ case CompoundType(Type[] parents, _):
+ break;
+ default:
+ int pos = closurePos(tp1.symbol());
+ assert pos >= 0 : this + " " + tp1 + " " + tp1.symbol();
+ closures.closure[pos] = tp1;
+ }
Type[] parents = tp1.parents();
for (int i = 0; i < parents.length; i++) {
adjustType(parents[i]);
@@ -1184,6 +1200,8 @@ public class ClassSymbol extends TypeSymbol {
*/
private Symbol thisSym = this;
+ public Symbol thisSym() { return thisSym; }
+
/** A cache for this.thisType()
*/
final private Type thistp = Type.ThisType(this);
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 2bec0ab167..2d6a000315 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -1154,6 +1154,14 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
}
}
+
+ Tree makeStableId(int pos, Type tp) {
+ if (tp.symbol().isCompoundSym())
+ return make.This(pos, Tree.Empty).setType(tp);
+ else
+ return gen.mkStableId(pos, tp);
+ }
+
/** Re-enter type parameters in current scope.
*/
void reenterParams(Tree[] params) {
@@ -1205,7 +1213,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
} else {
nextcontext = nextcontext.enclClass;
if (nextcontext != Context.NONE) {
- sym = nextcontext.owner.info().lookup(name);
+ sym = nextcontext.owner.thisSym().info().lookup(name);
if (sym.kind != NONE) {
stopPos = nextcontext.owner.pos;
} else {
@@ -1238,13 +1246,14 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
// evaluate what was found
if (sym1.kind == NONE) {
if (sym.kind == NONE) {
+ System.out.println(name);//debug
return error(tree.pos, "not found: " + decode(name));
} else {
sym.flags |= ACCESSED;
if (sym.owner().kind == CLASS) {
pre = nextcontext.enclClass.owner.thisType();
if (!sym.owner().isPackage()) {
- Tree qual = gen.mkStableId(tree.pos, pre);
+ Tree qual = makeStableId(tree.pos, pre);
tree = make.Select(tree.pos, qual, name);
//System.out.println(name + " :::> " + tree + " " + qual.symbol());//DEBUG
}
@@ -1835,6 +1844,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
/** The main attribution function
*/
public Tree transform(Tree tree) {
+ //new TextTreePrinter().print("transforming ").print(tree).println().end();//DEBUG
Symbol sym = tree.symbol();
if (sym != null && !sym.isInitialized()) sym.initialize();
if (global.debug && TreeInfo.isDefinition(tree)) global.log("transforming " + sym);
@@ -2163,7 +2173,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
if (qual == Tree.Empty) {
clazz = context.enclClass.owner;
if (clazz != null) {
- tree1 = gen.mkStableId(tree.pos, clazz.thisType());
+ tree1 = makeStableId(tree.pos, clazz.thisType());
} else {
return error(
tree.pos, tree +