diff options
author | Matthias Zenger <mzenger@gmail.com> | 2004-02-24 18:21:27 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2004-02-24 18:21:27 +0000 |
commit | 333d2fd8ba2ce9b9e21a0fd41baab6beb443c5f3 (patch) | |
tree | a6f1b682f665c69c2b09962ed4dc9e460adbfe50 /sources/scalac/symtab | |
parent | a634b2280f86d4884062c67b29879dc95eda8fd7 (diff) | |
download | scala-333d2fd8ba2ce9b9e21a0fd41baab6beb443c5f3.tar.gz scala-333d2fd8ba2ce9b9e21a0fd41baab6beb443c5f3.tar.bz2 scala-333d2fd8ba2ce9b9e21a0fd41baab6beb443c5f3.zip |
- Added support for static inner classes in Java
Diffstat (limited to 'sources/scalac/symtab')
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 106 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/AttributeParser.java | 44 |
2 files changed, 90 insertions, 60 deletions
diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index 17d05efe47..30aa4203b0 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -150,25 +150,25 @@ public class Definitions { public final Symbol[] TUPLE_CLASS = new Symbol[TUPLE_COUNT]; public final Type TUPLE_TYPE(Type[] args) { assert 0 < args.length && args.length < TUPLE_COUNT: args.length; - return getType(TUPLE_CLASS[args.length], args); + return getType(TUPLE_CLASS[args.length], args); } /** The scala.FunctionX classes */ public final int FUNCTION_COUNT = 10; public final Symbol[] FUNCTION_CLASS = new Symbol[FUNCTION_COUNT]; public final Type FUNCTION_TYPE(Type[] args, Type result) { - assert 0 <= args.length; - if (args.length >= FUNCTION_COUNT) - throw new Type.Error("function has too many arguments; limit = " + (FUNCTION_COUNT-1)); + assert 0 <= args.length; + if (args.length >= FUNCTION_COUNT) + throw new Type.Error("function has too many arguments; limit = " + (FUNCTION_COUNT-1)); args = Type.cloneArray(args, 1); args[args.length - 1] = result; - return getType(FUNCTION_CLASS[args.length - 1], args); + return getType(FUNCTION_CLASS[args.length - 1], args); } /** The scala.PartialFunction class */ public final Symbol PARTIALFUNCTION_CLASS; public final Type PARTIALFUNCTION_TYPE(Type argument, Type result) { - return getType(PARTIALFUNCTION_CLASS, new Type[] { argument, result }); + return getType(PARTIALFUNCTION_CLASS, new Type[] { argument, result }); } /** The scala.Iterable class */ @@ -186,7 +186,7 @@ public class Definitions { /** The scala.Seq class */ public final Symbol SEQ_CLASS; public final Type SEQ_TYPE(Type element) { - return getType(SEQ_CLASS, element); + return getType(SEQ_CLASS, element); } /** The scala.List class */ @@ -475,8 +475,8 @@ public class Definitions { // the top and bottom classes ANY_CLASS = newClass(SCALA_PACKAGE, Names.Any, 0); - ANYVAL_CLASS = getClass(Names.scala_AnyVal); - ANYREF_CLASS = newAlias(SCALA_PACKAGE, Names.AnyRef, 0); + ANYVAL_CLASS = getClass(Names.scala_AnyVal); + ANYREF_CLASS = newAlias(SCALA_PACKAGE, Names.AnyRef, 0); ALLREF_CLASS = newClass(SCALA_PACKAGE, Names.AllRef, 0); ALL_CLASS = newClass(SCALA_PACKAGE, Names.All, 0); @@ -497,7 +497,7 @@ public class Definitions { DOUBLE_CLASS = getClass(Names.scala_Double); // the scala reference classes - OBJECT_CLASS = getClass(Names.scala_ScalaObject); + OBJECT_CLASS = getClass(Names.scala_ScalaObject); STRING_CLASS = newAlias(SCALA_PACKAGE, Names.String, 0); REF_CLASS = getClass(Names.scala_Ref); for (int i = 1; i < TUPLE_COUNT; i++) { @@ -506,17 +506,17 @@ public class Definitions { } for (int i = 0; i < FUNCTION_COUNT; i++) FUNCTION_CLASS[i] = getClass(Names.scala_Function(i)); - PARTIALFUNCTION_CLASS = getClass(Names.scala_PartialFunction); - ITERABLE_CLASS = getClass(Names.scala_Iterable); - ITERATOR_CLASS = getClass(Names.scala_Iterator); - SEQ_CLASS = getClass(Names.scala_Seq); - LIST_CLASS = getClass(Names.scala_List); + PARTIALFUNCTION_CLASS = getClass(Names.scala_PartialFunction); + ITERABLE_CLASS = getClass(Names.scala_Iterable); + ITERATOR_CLASS = getClass(Names.scala_Iterator); + SEQ_CLASS = getClass(Names.scala_Seq); + LIST_CLASS = getClass(Names.scala_List); NIL = getModule(Names.scala_Nil); CONS_CLASS = getClass(Names.scala_COLONCOLON); ARRAY_CLASS = getClass(Names.scala_Array); PREDEF = getModule(Names.scala_Predef); CONSOLE = getModule(Names.scala_Console); - MATCHERROR = getModule(Names.scala_MatchError); + MATCHERROR = getModule(Names.scala_MatchError); // initialize generated classes and aliases initClass(ANY_CLASS, Type.EMPTY_ARRAY); @@ -541,7 +541,7 @@ public class Definitions { initAlias(STRING_CLASS, JAVA_STRING_TYPE()); // add members to scala.Any - ANY_EQ = newTerm(ANY_CLASS, Names.eq , 0); + ANY_EQ = newTerm(ANY_CLASS, Names.eq , 0); ANY_EQEQ = newTerm(ANY_CLASS, Names.EQEQ , Modifiers.FINAL); ANY_BANGEQ = newTerm(ANY_CLASS, Names.BANGEQ , Modifiers.FINAL); ANY_EQUALS = newTerm(ANY_CLASS, Names.equals , 0); @@ -566,17 +566,17 @@ public class Definitions { Symbol[] ANY_AS_TPARAMS = {newTParam(ANY_AS, 0, ANY_TYPE())}; ANY_AS.setInfo(Type.PolyType(ANY_AS_TPARAMS,ANY_AS_TPARAMS[0].type())); - Symbol[] ANY_MATCH_TPARAMS = { + Symbol[] ANY_MATCH_TPARAMS = { newTParam(ANY_MATCH, 0, ANY_TYPE()), newTParam(ANY_MATCH, 1, ANY_TYPE())}; - Symbol[] ANY_MATCH_VPARAMS = { + Symbol[] ANY_MATCH_VPARAMS = { newVParam(ANY_MATCH, 0, FUNCTION_TYPE( new Type[]{ANY_MATCH_TPARAMS[0].type()}, ANY_MATCH_TPARAMS[1].type()))}; ANY_MATCH.setInfo( - Type.PolyType( - ANY_MATCH_TPARAMS, - Type.MethodType( + Type.PolyType( + ANY_MATCH_TPARAMS, + Type.MethodType( ANY_MATCH_VPARAMS, ANY_MATCH_TPARAMS[1].type()))); @@ -584,14 +584,14 @@ public class Definitions { ANYREF_SYNCHRONIZED = newTerm(ANYREF_CLASS, Names.synchronized_, Modifiers.FINAL); - Symbol ANYREF_SYNCHRONIZED_TPARAM = + Symbol ANYREF_SYNCHRONIZED_TPARAM = newTParam(ANYREF_SYNCHRONIZED,0,ANY_TYPE()); - Symbol ANYREF_SYNCHRONIZED_VPARAM = + Symbol ANYREF_SYNCHRONIZED_VPARAM = newVParam(ANYREF_SYNCHRONIZED,0,ANYREF_SYNCHRONIZED_TPARAM.type()); ANYREF_SYNCHRONIZED.setInfo( - Type.PolyType( - new Symbol[] {ANYREF_SYNCHRONIZED_TPARAM}, - Type.MethodType( + Type.PolyType( + new Symbol[] {ANYREF_SYNCHRONIZED_TPARAM}, + Type.MethodType( new Symbol[] {ANYREF_SYNCHRONIZED_VPARAM}, ANYREF_SYNCHRONIZED_TPARAM.type()))); @@ -616,16 +616,16 @@ public class Definitions { // Public Methods /** Returns the symbol of the module with the given fullname. */ - public Symbol getModule(Name fullname) { - Scope scope = ROOT_CLASS.members(); + public Symbol getModule(Name fullname, boolean fail) { + Scope scope = ROOT_CLASS.members(); int i = 0; int j = fullname.pos((byte)'.', i); - while (j < fullname.length()) { - scope = scope.lookup(fullname.subName(i, j)).members(); - i = j + 1; - j = fullname.pos((byte)'.', i); - } - Symbol sym = scope.lookup(fullname.subName(i, fullname.length())); + while (j < fullname.length()) { + scope = scope.lookup(fullname.subName(i, j)).members(); + i = j + 1; + j = fullname.pos((byte)'.', i); + } + Symbol sym = scope.lookup(fullname.subName(i, fullname.length())); if (!sym.isModule()) { switch (sym.type()) { case OverloadedType(Symbol[] alts, Type[] alttypes): @@ -633,28 +633,34 @@ public class Definitions { if ((sym = alts[k]).isModule()) break; } } - assert sym.isModule() : "no module '" + fullname + "'"; + if (fail) + assert sym.isModule() : "no module '" + fullname + "'"; return sym; } + /** Returns the symbol of the module with the given fullname. */ + public Symbol getModule(Name fullname) { + return getModule(fullname, true); + } + /** Returns the symbol of the class with the given fullname. */ public Symbol getClass(Name fullname) { - Scope scope = ROOT_CLASS.members(); + Scope scope = ROOT_CLASS.members(); int i = 0; int j = fullname.pos((byte)'.', i); - while (j < fullname.length()) { - scope = scope.lookup(fullname.subName(i, j)).members(); - i = j + 1; - j = fullname.pos((byte)'.', i); - } - Symbol sym = scope.lookup(fullname.subName(i, fullname.length()).toTypeName()); - assert sym.kind != Kinds.NONE : "no class '" + fullname + "'"; - return sym; + while (j < fullname.length()) { + scope = scope.lookup(fullname.subName(i, j)).members(); + i = j + 1; + j = fullname.pos((byte)'.', i); + } + Symbol sym = scope.lookup(fullname.subName(i, fullname.length()).toTypeName()); + assert sym.kind != Kinds.NONE : "no class '" + fullname + "'"; + return sym; } /** Returns the type of the class with the given fullname. */ public Type getType(Name fullname) { - return getClass(fullname).type(); + return getClass(fullname).type(); } //######################################################################## @@ -688,15 +694,15 @@ public class Definitions { /** Creates a new type parameter */ private Symbol newTParam(Symbol owner, int index, Type bound) { Name name = Name.fromString("T" + index).toTypeName(); - return new AbsTypeSymbol(Position.NOPOS, name, owner, Modifiers.PARAM) - .setInfo(bound); + return new AbsTypeSymbol(Position.NOPOS, name, owner, Modifiers.PARAM) + .setInfo(bound); } /** Creates a new value parameter */ private Symbol newVParam(Symbol owner, int index, Type type) { Name name = Name.fromString("v" + index); return new TermSymbol(Position.NOPOS, name, owner, Modifiers.PARAM) - .setInfo(type); + .setInfo(type); } /** Creates a new type symbol */ @@ -759,7 +765,7 @@ public class Definitions { /** Returns the type of given class applied to given type argument. */ private Type getType(Symbol clasz, Type arg) { - return getType(clasz, new Type[] { arg }); + return getType(clasz, new Type[] { arg }); } /** Returns the type of given class applied to given type arguments. */ diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java index 76972808d6..b5cdc6006d 100644 --- a/sources/scalac/symtab/classfile/AttributeParser.java +++ b/sources/scalac/symtab/classfile/AttributeParser.java @@ -98,19 +98,43 @@ public class AttributeParser implements ClassfileConstants { new UnPickle(sym, in.nextBytes(attrLen), Name.fromString(in.path)); return; case INNERCLASSES_ATTR: - /* int n = in.nextChar(); + int n = in.nextChar(); + //System.out.println(sym + " has " + n + " innerclass entries"); for (int i = 0; i < n; i++) { - Symbol inner = (Symbol)pool.readPool(in.nextChar()); - Symbol outer = (Symbol)pool.readPool(in.nextChar()); Name name = (Name)pool.readPool(in.nextChar()); - int flags = in.nextChar(); - if (name != null) { - // inner.owner(outer); - // inner.mangled(name); - // inner.flags = flags; + if (name == null) { + in.nextChar(); + in.nextChar(); + in.nextChar(); + continue; } - } */ - in.skip(attrLen); + Symbol inner = parser.global.definitions.getClass(name); + name = (Name)pool.readPool(in.nextChar()); + if (name == null) { + in.nextChar(); + in.nextChar(); + continue; + } + Symbol outer = parser.global.definitions.getModule(name, false); + name = (Name)pool.readPool(in.nextChar()); + int flags = in.nextChar(); + if ((name == null) || + ((flags & 0x0009) == 0) || + ((flags & 0x0001) == 0) || + !outer.isModule() || + (outer != sym.module())) + continue; + AliasTypeSymbol alias = + new AliasTypeSymbol(Position.NOPOS, name.toTypeName(), outer, 0); + alias.setFirstInfo(inner.typeConstructor()); + alias.allConstructors() + .setInfo(new Type.MethodType(Symbol.EMPTY_ARRAY, inner.info())); + Scope.Entry e = parser.statics.lookupEntry(alias.name); // Why is this ?????? + if (e != Scope.Entry.NONE) + parser.statics.unlink(e); + parser.statics.enter(alias); + } + //in.skip(attrLen); return; // method attributes case CODE_ATTR: |