diff options
author | Martin Odersky <odersky@gmail.com> | 2003-03-07 14:56:14 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-03-07 14:56:14 +0000 |
commit | a6e24444781bd5d1d492b2f914177126df2884b1 (patch) | |
tree | fb39eb1150604a535bed2e01258cf1fb9be62062 /sources | |
parent | b1276c1eca5cf13950544ca3caddce3b6eb90c86 (diff) | |
download | scala-a6e24444781bd5d1d492b2f914177126df2884b1.tar.gz scala-a6e24444781bd5d1d492b2f914177126df2884b1.tar.bz2 scala-a6e24444781bd5d1d492b2f914177126df2884b1.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scalac/ast/parser/Parser.java | 6 | ||||
-rw-r--r-- | sources/scalac/symtab/Type.java | 34 | ||||
-rw-r--r-- | sources/scalac/typechecker/Infer.java | 27 |
3 files changed, 48 insertions, 19 deletions
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java index 3d8d79fabb..518ded67e6 100644 --- a/sources/scalac/ast/parser/Parser.java +++ b/sources/scalac/ast/parser/Parser.java @@ -1662,9 +1662,15 @@ public class Parser implements Tokens { } else if (isDefIntro()) { stats.append(defOrDcl(0)); accept(SEMI); + if (s.token == RBRACE) { + stats.append(make.Block(s.pos, Tree.EMPTY_ARRAY)); + } } else if (isLocalClassModifier()) { stats.append(topDef(localClassModifiers())); accept(SEMI); + if (s.token == RBRACE) { + stats.append(make.Block(s.pos, Tree.EMPTY_ARRAY)); + } } else if (s.token == SEMI) { s.nextToken(); } else { diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index 5c7790fb72..fdba7b8f40 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -924,35 +924,39 @@ public class Type implements Modifiers, Kinds, TypeTags { /** A common map superclass for symbol/symbol and type/symbol substitutions. */ - static abstract class SubstMap extends Map { + public static abstract class SubstMap extends Map { private Symbol[] from; SubstMap(Symbol[] from) { this.from = from; } + public boolean matches(Symbol sym1, Symbol sym2) { + return sym1 == sym2; + } + /** Produce replacement type * @param i The index in `from' of the symbol to be replaced. * @param fromtp The type referring to this symbol. */ - abstract Type replacement(int i, Type fromtp); + protected abstract Type replacement(int i, Type fromtp); /** Produce new substitution where some symbols are excluded. * @param newfrom The new array of from symbols (without excluded syms) * @param excluded The array of excluded sysmbols */ - abstract SubstMap exclude(Symbol[] newfrom, Symbol[] excluded); + protected abstract SubstMap exclude(Symbol[] newfrom, Symbol[] excluded); public Type apply(Type t) { switch (t) { case TypeRef(ThisType(_), Symbol sym, Type[] args): for (int i = 0; i < from.length; i++) { - if (sym == from[i]) return replacement(i, t); + if (matches(sym, from[i])) return replacement(i, t); } break; case SingleType(ThisType(_), Symbol sym): for (int i = 0; i < from.length; i++) { - if (sym == from[i]) return replacement(i, t); + if (matches(sym, from[i])) return replacement(i, t); } break; case PolyType(Symbol[] tparams, Type result): @@ -1015,13 +1019,13 @@ public class Type implements Modifiers, Kinds, TypeTags { /** A map for symbol/symbol substitutions */ - static class SubstSymMap extends SubstMap { + public static class SubstSymMap extends SubstMap { Symbol[] to; - SubstSymMap(Symbol[] from, Symbol[] to) { + protected SubstSymMap(Symbol[] from, Symbol[] to) { super(from); this.to = to; } - Type replacement(int i, Type fromtp) { + protected Type replacement(int i, Type fromtp) { switch (fromtp) { case TypeRef(Type pre, Symbol sym, Type[] args): return TypeRef(pre, to[i], args); @@ -1031,23 +1035,23 @@ public class Type implements Modifiers, Kinds, TypeTags { throw new ApplicationError(); } } - SubstMap exclude(Symbol[] newfrom, Symbol[] excluded) { + protected SubstMap exclude(Symbol[] newfrom, Symbol[] excluded) { return new SubstSymMap(newfrom, excludeSyms(from, excluded, to)); } } /** A map for type/symbol substitutions */ - static class SubstTypeMap extends SubstMap { + public static class SubstTypeMap extends SubstMap { Type[] to; - SubstTypeMap(Symbol[] from, Type[] to) { + protected SubstTypeMap(Symbol[] from, Type[] to) { super(from); this.to = to; } - Type replacement(int i, Type fromtp) { + protected Type replacement(int i, Type fromtp) { return to[i]; } - SubstMap exclude(Symbol[] newfrom, Symbol[] excluded) { + protected SubstMap exclude(Symbol[] newfrom, Symbol[] excluded) { return new SubstTypeMap(newfrom, excludeTypes(from, excluded, to)); } } @@ -1092,10 +1096,10 @@ public class Type implements Modifiers, Kinds, TypeTags { /** A map for substitutions of thistypes. */ - static class SubstThisMap extends Map { + public static class SubstThisMap extends Map { Symbol from; Type to; - SubstThisMap(Symbol from, Type to) { + protected SubstThisMap(Symbol from, Type to) { this.from = from; this.to = to; } diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java index 9da7ef13d8..2a5a638004 100644 --- a/sources/scalac/typechecker/Infer.java +++ b/sources/scalac/typechecker/Infer.java @@ -87,6 +87,7 @@ public class Infer implements Modifiers, Kinds { Symbol[] tparams; Type[] targs; TreeGen gen; + Type.SubstTypeMap typeSubstituter; public Substituter(Global global, PhaseDescriptor descr, TreeGen gen) { super(global, descr); @@ -96,6 +97,12 @@ public class Infer implements Modifiers, Kinds { public Tree apply(Tree tree, Symbol[] tparams, Type[] targs) { this.tparams = tparams; this.targs = targs; + this.typeSubstituter = new Type.SubstTypeMap(tparams, targs) { + public boolean matches(Symbol sym1, Symbol sym2) { + return + sym1.name == sym2.name && sym1.owner() == sym2.owner(); + } + }; return transform(tree); } @@ -116,20 +123,32 @@ public class Infer implements Modifiers, Kinds { public Tree transform(Tree tree) { // System.out.println("[" + ArrayApply.toString(targs,"",",","") + "/" + ArrayApply.toString(tparams,"",",","") + "]" + tree + "@" + tree.symbol());//DEBUG - if (tree.type == null) return tree; - tree.type = elimInferredPolyMap.apply(tree.type).subst(tparams, targs); + if (tree.type != null) { + tree.type = typeSubstituter.apply( + elimInferredPolyMap.apply(tree.type)); + } switch (tree) { case Ident(Name name): if (name.isTypeName()) { Symbol sym = tree.symbol(); for (int i = 0; i < tparams.length; i++) { - if (tparams[i].name == sym.name && - tparams[i].owner() == sym.owner()) { + if (typeSubstituter.matches(tparams[i], sym)) { return gen.mkType(tree.pos, targs[i]); } } } return tree; +/* + case TypeTerm(): + Symbol sym = tree.type.symbol(); + for (int i = 0; i < tparams.length; i++) { + if (tparams[i].name == sym.name && + tparams[i].owner() == sym.owner()) { + return gen.mkType(tree.pos, targs[i]); + } + } + return tree; +*/ default: return super.transform(tree); } |