diff options
author | paltherr <paltherr@epfl.ch> | 2004-01-08 18:27:00 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2004-01-08 18:27:00 +0000 |
commit | 9d7f21f57304c2b5077aad06ead9d6b2847733f7 (patch) | |
tree | 4237f924a42f895230b2522fb7dec98ec2977ef2 /sources | |
parent | b8d2c4e065e3b263efa10ec95d8000317fa17e1f (diff) | |
download | scala-9d7f21f57304c2b5077aad06ead9d6b2847733f7.tar.gz scala-9d7f21f57304c2b5077aad06ead9d6b2847733f7.tar.bz2 scala-9d7f21f57304c2b5077aad06ead9d6b2847733f7.zip |
- Added constants NIL, CONS, PREDEF, ARRAY_LENG...
- Added constants NIL, CONS, PREDEF, ARRAY_LENGTH, ARRAY_GET and
ARRAY_SET
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index f8564aa25f..4e4f9242fd 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -188,6 +188,15 @@ public class Definitions { return getType(LIST_CLASS, element); } + /** The scala.Nil module */ + public final Symbol NIL; + + /** The scala.:: class */ + public final Symbol CONS_CLASS; + public final Type CONS_TYPE(Type element) { + return getType(CONS_CLASS, element); + } + /** The scala.Array class */ public final Symbol ARRAY_CLASS; public final Type ARRAY_TYPE(Type element) { @@ -202,6 +211,9 @@ public class Definitions { } } + /** The scala.Predef module */ + public final Symbol PREDEF; + /** The scala.Console module */ public final Symbol CONSOLE; @@ -361,12 +373,44 @@ public class Definitions { return LIST_TAIL; } + /** The scala.Array class */ + private Symbol ARRAY_LENGTH; + private Symbol ARRAY_GET; + private Symbol ARRAY_SET; + + public Symbol ARRAY_LENGTH() { + if (ARRAY_LENGTH == null) + ARRAY_LENGTH = loadTerm(ARRAY_CLASS, Names.length); + return ARRAY_LENGTH; + } + + public Symbol ARRAY_GET() { + if (ARRAY_GET == null) + ARRAY_GET = loadTerm(ARRAY_CLASS, Names.apply, new Type[]{INT_TYPE()}); + return ARRAY_GET; + } + + public Symbol ARRAY_SET() { + if (ARRAY_SET == null) + ARRAY_SET = loadTerm(ARRAY_CLASS, Names.update); + return ARRAY_SET; + } + + /** Some scala.Predef methods */ + private Symbol PREDEF_ARRAY; + + public Symbol PREDEF_ARRAY() { + if (PREDEF_ARRAY == null) + PREDEF_ARRAY = loadTerm(PREDEF, Names.Array); + return PREDEF_ARRAY; + } + /** Some scala.Console methods */ private Symbol CONSOLE_PRINT; public Symbol CONSOLE_PRINT() { - if( CONSOLE_PRINT == null ) - CONSOLE_PRINT = loadTerm( CONSOLE, Names.print ); + if (CONSOLE_PRINT == null) + CONSOLE_PRINT = loadTerm(CONSOLE, Names.print); return CONSOLE_PRINT; } @@ -461,7 +505,10 @@ public class Definitions { 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 = getModule(Names.scala_COLONCOLON); ARRAY_CLASS = getClass(Names.scala_Array); + PREDEF = getModule(Names.scala_Predef); CONSOLE = getModule(Names.scala_Console); MATCHERROR = getModule(Names.scala_MatchError); @@ -664,6 +711,28 @@ public class Definitions { return sym; } + /** + * Returns the term member of given class with given name and + * value argument types. + */ + private Symbol loadTerm(Symbol clasz, Name name, Type[] vargs) { + Symbol sym = clasz.lookup(name); + assert sym.isTerm(): Debug.show(clasz,"."+name+" - ",vargs," -> ",sym); + Symbol[] alts = sym.alternativeSymbols(); + for (int i = 0; i < alts.length; i++) { + switch (alts[i].type()) { + case PolyType(_, MethodType(Symbol[] vparams, _)): + if (Type.isSameAs(Symbol.type(vparams), vargs)) return alts[i]; + continue; + case MethodType(Symbol[] vparams, _): + if (Type.isSameAs(Symbol.type(vparams), vargs)) return alts[i]; + continue; + } + } + throw Debug.abort(Debug.show(clasz,"."+name+" - ",vargs," -> ",alts)); + } + + /** Returns the type of given class applied to given type argument. */ private Type getType(Symbol clasz, Type arg) { return getType(clasz, new Type[] { arg }); |