summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/Definitions.java
blob: aaac2ee96095338b0b1d15ed29211dd2a28c0fea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**                                                                      **
** $Id$
\*                                                                      */

package scalac.symtab;

import ch.epfl.lamp.util.Position;

import scalac.Global;
import scalac.symtab.classfile.PackageParser;
import scalac.util.Debug;
import scalac.util.Name;
import scalac.util.Names;

public class Definitions {

    //########################################################################
    // Public Fields & Methods - Root module

    /** The root module */
    public final Symbol ROOT;
    public final Symbol ROOT_CLASS;
    public final Type   ROOT_TYPE() {return ROOT_CLASS.type();}

    //########################################################################
    // Public Fields & Methods - Top and bottom classes

    /** The scala.Any class */
    public final Symbol ANY_CLASS;
    public final Type   ANY_TYPE() {return ANY_CLASS.type();}

    /** The scala.AnyVal class */
    public final Symbol ANYVAL_CLASS;
    public final Type   ANYVAL_TYPE() {return ANYVAL_CLASS.type();}

    /** The scala.AnyRef class */
    public final Symbol ANYREF_CLASS;
    public final Type   ANYREF_TYPE() {return ANYREF_CLASS.type();}

    /** The scala.AllRef class */
    public final Symbol ALLREF_CLASS;
    public final Type   ALLREF_TYPE() {return ALLREF_CLASS.type();}

    /** The scala.All class */
    public final Symbol ALL_CLASS;
    public final Type   ALL_TYPE() {return ALL_CLASS.type();}

    //########################################################################
    // Public Fields & Methods - Java classes

    /** The java.lang.Object class */
    public final Symbol JAVA_OBJECT_CLASS;
    public final Type   JAVA_OBJECT_TYPE() {return JAVA_OBJECT_CLASS.type();}

    /** The java.lang.String class */
    public final Symbol JAVA_STRING_CLASS;
    public final Type   JAVA_STRING_TYPE() {return JAVA_STRING_CLASS.type();}

    /** The java.lang.Throwable class */
    public final Symbol JAVA_THROWABLE_CLASS;
    public final Type   JAVA_THROWABLE_TYPE() {return JAVA_THROWABLE_CLASS.type();}

    //########################################################################
    // Public Fields & Methods - Scala value classes

    /** The scala.Unit class */
    public final Symbol UNIT_CLASS;
    public final Type   UNIT_TYPE() {
        return UNIT_TYPE.type().resultType();
    }

    /** The scala.Boolean class */
    public final Symbol BOOLEAN_CLASS;
    public final Type   BOOLEAN_TYPE() {
        return BOOLEAN_TYPE.type().resultType();
    }

    /** The scala.Byte class */
    public final Symbol BYTE_CLASS;
    public final Type   BYTE_TYPE() {
        return BYTE_TYPE.type().resultType();
    }

    /** The scala.Short class */
    public final Symbol SHORT_CLASS;
    public final Type   SHORT_TYPE() {
        return SHORT_TYPE.type().resultType();
    }

    /** The scala.Char class */
    public final Symbol CHAR_CLASS;
    public final Type   CHAR_TYPE() {
        return CHAR_TYPE.type().resultType();
    }

    /** The scala.Int class */
    public final Symbol INT_CLASS;
    public final Type   INT_TYPE() {
        return INT_TYPE.type().resultType();
    }

    /** The scala.Long class */
    public final Symbol LONG_CLASS;
    public final Type   LONG_TYPE() {
        return LONG_TYPE.type().resultType();
    }

    /** The scala.Float class */
    public final Symbol FLOAT_CLASS;
    public final Type   FLOAT_TYPE() {
        return FLOAT_TYPE.type().resultType();
    }

    /** The scala.Double class */
    public final Symbol DOUBLE_CLASS;
    public final Type   DOUBLE_TYPE() {
        return DOUBLE_TYPE.type().resultType();
    }

    //########################################################################
    // Public Fields & Methods - Scala reference classes

    /** The scala.Object class */
    public final Symbol OBJECT_CLASS;
    public final Type   OBJECT_TYPE() {return OBJECT_CLASS.type();}

    /** The scala.String class */
    public final Symbol STRING_CLASS;
    public final Type   STRING_TYPE() {return STRING_CLASS.type();}

    /** The scala.Ref class */
    public final Symbol REF_CLASS;
    public final Type   REF_TYPE(Type element) {
        return getType(REF_CLASS, element);
    }

    /** The scala.TupleX classes */
    public final int      TUPLE_COUNT = 10;
    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);
    }

    /** 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));
        args = Type.cloneArray(args, 1);
        args[args.length - 1] = result;
	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 });
    }

    /** The scala.Iterable class */
    public final Symbol ITERABLE_CLASS;
    public final Type   ITERABLE_TYPE(Type element) {
        return getType(ITERABLE_CLASS, element);
    }

    /** The scala.Iterator class */
    public final Symbol ITERATOR_CLASS;
    public final Type   ITERATOR_TYPE(Type element) {
        return getType(ITERATOR_CLASS, element);
    }

    /** The scala.Seq class */
    public final Symbol SEQ_CLASS;
    public final Type   SEQ_TYPE(Type element) {
	return getType(SEQ_CLASS, element);
    }

    /** The scala.List class */
    public final Symbol LIST_CLASS;
    public final Type   LIST_TYPE(Type element) {
        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) {
        Type type = ARRAY_TYPE.type().resultType();
        switch (type) {
        case TypeRef(Type prefix, Symbol clasz, _):
            return Type.typeRef(prefix, clasz, new Type[]{element});
        case UnboxedArrayType(_):
            return Type.UnboxedArrayType(element);
        default:
            throw Debug.abort("illegal case", type);
        }
    }

    /** The scala.Predef module */
    public final Symbol PREDEF;

    /** The scala.Console module */
    public final Symbol CONSOLE;

    /** The scala.MatchError module */
    public final Symbol MATCHERROR;

    //########################################################################
    // Public Fields & Methods - Top and bottom class methods

    /** Some scala.Any methods */
    public final Symbol ANY_EQ;
    public final Symbol ANY_EQEQ;
    public final Symbol ANY_BANGEQ;
    public final Symbol ANY_EQUALS;
    public final Symbol ANY_HASHCODE;
    public final Symbol ANY_TOSTRING;
    //public final Symbol ANY_PLUS;
    public final Symbol ANY_IS;
    public final Symbol ANY_AS;
    public final Symbol ANY_MATCH;

    /** Some scala.AnyRef methods */
    public final Symbol ANYREF_SYNCHRONIZED;

    //########################################################################
    // Public Fields & Methods - Java class methods

    /** Some java.lang.String methods */
    public final Symbol JAVA_STRING_PLUS;

    /** Some java.lang.Throwable methods */
    public final Symbol JAVA_THROWABLE_THROW;

    //########################################################################
    // Public Fields & Methods - Scala value class methods

    /** Some scala.Boolean methods */
    private Symbol BOOLEAN_OR;
    private Symbol BOOLEAN_AND;
    private Symbol BOOLEAN_NOT;

    public Symbol BOOLEAN_OR() {
        if (BOOLEAN_OR == null)
            BOOLEAN_OR = loadTerm(BOOLEAN_CLASS, Names.BARBAR);
        return BOOLEAN_OR;
    }
    public Symbol BOOLEAN_AND() {
        if (BOOLEAN_AND == null)
            BOOLEAN_AND = loadTerm(BOOLEAN_CLASS, Names.AMPAMP);
        return BOOLEAN_AND;
    }
    public Symbol BOOLEAN_NOT() {
        if (BOOLEAN_NOT == null)
            BOOLEAN_NOT = loadTerm(BOOLEAN_CLASS, Names.BANG);
        return BOOLEAN_NOT;
    }

    //########################################################################
    // Public Fields & Methods - Scala reference class methods

    /** Some scala.Object methods */
    private Symbol OBJECT_TAG;

    public Symbol OBJECT_TAG() {
        if (OBJECT_TAG == null)
            OBJECT_TAG = loadTerm(OBJECT_CLASS, Names.tag);
        return OBJECT_TAG;
    }

    /** Some scala.Ref methods */
    private Symbol REF_ELEM;

    public Symbol REF_ELEM() {
        if (REF_ELEM == null)
            REF_ELEM = loadTerm(REF_CLASS, Names.elem);
        return REF_ELEM;
    }

    /** Some scala.TupleX methods */
    private final Symbol[][] TUPLE_FIELD = new Symbol[TUPLE_COUNT][];

    public Symbol TUPLE_FIELD(int arity, int index) {
        assert 0 < arity && arity < TUPLE_COUNT: arity;
        assert 0 < index && index <= arity: arity + " - " + index;
        if (TUPLE_FIELD[arity][index - 1] == null)
            TUPLE_FIELD[arity][index - 1] = loadTerm(TUPLE_CLASS[arity],Names.TUPLE_FIELD(index));
        return TUPLE_FIELD[arity][index - 1];
    }

    /** Some scala.FunctionX methods */
    private final Symbol[] FUNCTION_APPLY = new Symbol[FUNCTION_COUNT];

    public Symbol FUNCTION_APPLY(int arity) {
        assert 0 <= arity && arity < FUNCTION_COUNT: arity;
        if (FUNCTION_APPLY[arity] == null)
            FUNCTION_APPLY[arity] = loadTerm(FUNCTION_CLASS[arity],Names.apply);
        return FUNCTION_APPLY[arity];
    }

    /** Some scala.PartialFunction methods */
    private Symbol PARTIALFUNCTION_ISDEFINEDAT;

    public Symbol PARTIALFUNCTION_ISDEFINEDAT() {
        if (PARTIALFUNCTION_ISDEFINEDAT == null)
            PARTIALFUNCTION_ISDEFINEDAT = loadTerm(PARTIALFUNCTION_CLASS, Names.isDefinedAt);
        return PARTIALFUNCTION_ISDEFINEDAT;
    }

    /** Some scala.Iterable methods */
    private Symbol ITERABLE_ELEMENTS;

    public Symbol ITERABLE_ELEMENTS() {
        if (ITERABLE_ELEMENTS == null)
            ITERABLE_ELEMENTS = loadTerm(ITERABLE_CLASS, Names.elements);
        return ITERABLE_ELEMENTS;
    }

    /** Some scala.Iterator methods */
    private Symbol ITERATOR_NEXT;
    private Symbol ITERATOR_HASNEXT;

    public Symbol ITERATOR_NEXT() {
        if (ITERATOR_NEXT == null)
            ITERATOR_NEXT = loadTerm(ITERATOR_CLASS, Names.next);
        return ITERATOR_NEXT;
    }
    public Symbol ITERATOR_HASNEXT() {
        if (ITERATOR_HASNEXT == null)
            ITERATOR_HASNEXT = loadTerm(ITERATOR_CLASS, Names.hasNext);
        return ITERATOR_HASNEXT;
    }

    /** Some scala.Seq methods */
    private Symbol SEQ_LENGTH;

    public Symbol SEQ_LENGTH() {
        if (SEQ_LENGTH == null)
            SEQ_LENGTH = loadTerm(SEQ_CLASS, Names.length);
        return SEQ_LENGTH;
    }

    /** Some scala.List methods */
    private Symbol LIST_ISEMPTY;
    private Symbol LIST_HEAD;
    private Symbol LIST_TAIL;

    public Symbol LIST_ISEMPTY() {
        if (LIST_ISEMPTY == null)
            LIST_ISEMPTY = loadTerm(LIST_CLASS, Names.isEmpty);
        return LIST_ISEMPTY;
    }
    public Symbol LIST_HEAD() {
        if (LIST_HEAD == null)
            LIST_HEAD = loadTerm(LIST_CLASS, Names.head);
        return LIST_HEAD;
    }
    public Symbol LIST_TAIL() {
        if (LIST_TAIL == null)
            LIST_TAIL = loadTerm(LIST_CLASS, Names.tail);
        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);
        return CONSOLE_PRINT;
    }

    /** Some scala.MatchError methods */
    private Symbol MATCHERROR_FAIL;

    public Symbol MATCHERROR_FAIL() {
        if (MATCHERROR_FAIL == null)
            MATCHERROR_FAIL = loadTerm(MATCHERROR, Names.fail);
        return MATCHERROR_FAIL;
    }

    //########################################################################
    // Public Fields - Global values

    /** The null value */
    public final Symbol NULL;

    /** The zero value (a default null for type variables with bound Any) */
    public final Symbol ZERO;

    /** The universal pattern */
    public final Symbol PATTERN_WILDCARD;

    //########################################################################
    // Private Fields - Symbol

    private final Symbol UNIT_TYPE;
    private final Symbol BOOLEAN_TYPE;
    private final Symbol BYTE_TYPE;
    private final Symbol SHORT_TYPE;
    private final Symbol CHAR_TYPE;
    private final Symbol INT_TYPE;
    private final Symbol LONG_TYPE;
    private final Symbol FLOAT_TYPE;
    private final Symbol DOUBLE_TYPE;
    private final Symbol ARRAY_TYPE;

    //########################################################################
    // Public Constructor

    /** Initializes this instance. */
    public Definitions(Global global) {
        // make definitions accessible earlier to other components
        global.definitions = this;
        // force initialization of class Type
        Type.localThisType.symbol();

        // the root module
        ROOT = TermSymbol.newJavaPackageModule(
            Names.ROOT, Symbol.NONE, new PackageParser(global));
        ROOT_CLASS = ROOT.moduleClass();

        // the scala package
        Symbol SCALA_PACKAGE = getClass(Names.scala);

        // 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);
        ALLREF_CLASS = newClass(SCALA_PACKAGE, Names.AllRef, 0);
        ALL_CLASS = newClass(SCALA_PACKAGE, Names.All, 0);

        // the java classes
        JAVA_OBJECT_CLASS = getClass(Names.java_lang_Object);
        JAVA_THROWABLE_CLASS = getClass(Names.java_lang_Throwable);
        JAVA_STRING_CLASS = getClass(Names.java_lang_String);

        // the scala value classes
        UNIT_CLASS = getClass(Names.scala_Unit);
        BOOLEAN_CLASS = getClass(Names.scala_Boolean);
        BYTE_CLASS = getClass(Names.scala_Byte);
        SHORT_CLASS = getClass(Names.scala_Short);
        CHAR_CLASS = getClass(Names.scala_Char);
        INT_CLASS = getClass(Names.scala_Int);
        LONG_CLASS = getClass(Names.scala_Long);
        FLOAT_CLASS = getClass(Names.scala_Float);
        DOUBLE_CLASS = getClass(Names.scala_Double);

        // the scala reference classes
	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++) {
            TUPLE_CLASS[i] = getClass(Names.scala_Tuple(i));
            TUPLE_FIELD[i] = new Symbol[i];
        }
        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);
        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);

        // initialize generated classes and aliases
        initClass(ANY_CLASS, Type.EMPTY_ARRAY);
        initAlias(ANYREF_CLASS, JAVA_OBJECT_TYPE());
        initClass(ALLREF_CLASS, new Type[]{ANYREF_TYPE()});
        initClass(ALL_CLASS, new Type[]{ANY_TYPE()});
        initAlias(STRING_CLASS, JAVA_STRING_TYPE());

        // create type symbols
        UNIT_TYPE    = newTypeSymbol(Names.Unit   , UNIT_CLASS.type   ());
        BOOLEAN_TYPE = newTypeSymbol(Names.Boolean, BOOLEAN_CLASS.type());
        BYTE_TYPE    = newTypeSymbol(Names.Byte   , BYTE_CLASS.type   ());
        SHORT_TYPE   = newTypeSymbol(Names.Short  , SHORT_CLASS.type  ());
        CHAR_TYPE    = newTypeSymbol(Names.Char   , CHAR_CLASS.type   ());
        INT_TYPE     = newTypeSymbol(Names.Int    , INT_CLASS.type    ());
        LONG_TYPE    = newTypeSymbol(Names.Long   , LONG_CLASS.type   ());
        FLOAT_TYPE   = newTypeSymbol(Names.Float  , FLOAT_CLASS.type  ());
        DOUBLE_TYPE  = newTypeSymbol(Names.Double , DOUBLE_CLASS.type ());
        ARRAY_TYPE   = newTypeSymbol(Names.Array  ,
            Type.appliedType(ARRAY_CLASS.type(), new Type[]{ANYREF_TYPE()}));

        // add members to scala.Any
	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);
        ANY_HASHCODE = newTerm(ANY_CLASS, Names.hashCode    , 0);
        ANY_TOSTRING = newTerm(ANY_CLASS, Names.toString    , 0);
        // ANY_PLUS  = newTerm(ANY_CLASS, Names.PLUS        , Modifiers.FINAL);
        ANY_IS       = newTerm(ANY_CLASS, Names.isInstanceOf, Modifiers.FINAL);
        ANY_AS       = newTerm(ANY_CLASS, Names.asInstanceOf, Modifiers.FINAL);
        ANY_MATCH    = newTerm(ANY_CLASS, Names.match       , Modifiers.FINAL);

        initMethod(ANY_EQ      , new Type[]{ANY_TYPE()}   , BOOLEAN_TYPE());
        initMethod(ANY_EQEQ    , new Type[]{ANY_TYPE()}   , BOOLEAN_TYPE());
        initMethod(ANY_BANGEQ  , new Type[]{ANY_TYPE()}   , BOOLEAN_TYPE());
        initMethod(ANY_EQUALS  , new Type[]{ANY_TYPE()}   , BOOLEAN_TYPE());
        initMethod(ANY_HASHCODE, new Type[]{}             , INT_TYPE());
        initMethod(ANY_TOSTRING, new Type[]{}             , STRING_TYPE());
        // initMethod(ANY_PLUS , new Type[]{STRING_TYPE()}, STRING_TYPE());

        Symbol[] ANY_IS_TPARAMS = {newTParam(ANY_IS, 0, ANY_TYPE())};
        ANY_IS.setInfo(Type.PolyType(ANY_IS_TPARAMS, BOOLEAN_TYPE()));

        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 = {
            newTParam(ANY_MATCH, 0, ANY_TYPE()),
            newTParam(ANY_MATCH, 1, ANY_TYPE())};
	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(
                    ANY_MATCH_VPARAMS,
                    ANY_MATCH_TPARAMS[1].type())));

        // add members to scala.AnyREF
        ANYREF_SYNCHRONIZED =
            newTerm(ANYREF_CLASS, Names.synchronized_, Modifiers.FINAL);

	Symbol ANYREF_SYNCHRONIZED_TPARAM =
            newTParam(ANYREF_SYNCHRONIZED,0,ANY_TYPE());
	Symbol ANYREF_SYNCHRONIZED_VPARAM =
            newVParam(ANYREF_SYNCHRONIZED,0,ANYREF_SYNCHRONIZED_TPARAM.type());
        ANYREF_SYNCHRONIZED.setInfo(
	    Type.PolyType(
		new Symbol[] {ANYREF_SYNCHRONIZED_TPARAM},
		Type.MethodType(
                    new Symbol[] {ANYREF_SYNCHRONIZED_VPARAM},
                    ANYREF_SYNCHRONIZED_TPARAM.type())));

        // add members to java.lang.String
        JAVA_STRING_PLUS =
            newTerm(JAVA_STRING_CLASS, Names.PLUS, Modifiers.FINAL);
        initMethod(JAVA_STRING_PLUS, new Type[]{ANY_TYPE()}, STRING_TYPE());

        // add members to java.lang.Throwable
        JAVA_THROWABLE_THROW =
            newTerm(JAVA_THROWABLE_CLASS, Names.throw_, Modifiers.FINAL);
        JAVA_THROWABLE_THROW.setInfo(
            Type.PolyType(Symbol.EMPTY_ARRAY, ALL_TYPE()));

        // create global values
	NULL = newTerm(ROOT_CLASS, Names.null_, 0).setInfo(ALLREF_TYPE());
	ZERO = newTerm(ROOT_CLASS, Names.ZERO, 0).setInfo(ALL_TYPE());
        PATTERN_WILDCARD = newTerm(ROOT_CLASS, Names.PATTERN_WILDCARD, 0)
            .setType(ALL_TYPE());
    }

    //########################################################################
    // Public Methods

    /** Returns the symbol of the module with the given fullname. */
    public Symbol getModule(Name fullname) {
	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()));
        if (!sym.isModule()) {
            switch (sym.type()) {
            case OverloadedType(Symbol[] alts, Type[] alttypes):
                for (int k = 0; k < alts.length; k++)
                    if ((sym = alts[k]).isModule()) break;
            }
        }
        assert sym.isModule() : "no module '" + fullname + "'";
        return sym;
    }

    /** Returns the symbol of the class with the given fullname. */
    public Symbol getClass(Name fullname) {
	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;
    }

    /** Returns the type of the class with the given fullname. */
    public Type getType(Name fullname) {
	return getClass(fullname).type();
    }

    //########################################################################
    // Private Methods

    /** Creates a new class */
    private Symbol newClass(Symbol owner, Name name, int flags) {
        name = name.toTypeName();
        Symbol clasz = new ClassSymbol(Position.NOPOS, name, owner, flags);
        owner.members().enter(clasz);
        return clasz;
    }

    /** Creates a new type alias */
    private Symbol newAlias(Symbol owner, Name name, int flags) {
        name = name.toTypeName();
        Symbol alias = new AliasTypeSymbol(Position.NOPOS, name, owner, flags);
        owner.members().enter(alias);
        return alias;
    }

    /** Creates a new term */
    private Symbol newTerm(Symbol owner, Name name, int flags) {
        if (owner.isTypeAlias()) owner = owner.type().unalias().symbol();
        assert owner.isClassType(): Debug.show(owner) + " -- " + name;
        Symbol method = new TermSymbol(Position.NOPOS, name, owner, flags);
        if (owner != Symbol.NONE) owner.members().enterOrOverload(method);
        return method;
    }

    /** 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);
    }

    /** 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);
    }

    /** Creates a new type symbol */
    private Symbol newTypeSymbol(Name name, Type type) {
        Symbol symbol = new TermSymbol(Position.NOPOS, name, ROOT_CLASS, 0);
        initMethod(symbol, Type.EMPTY_ARRAY, type);
        return symbol;
    }

    /** Initializes the given class */
    private void initClass(Symbol clasz, Type[] parents) {
        clasz.setInfo(Type.compoundType(parents, new Scope(), clasz));
        clasz.primaryConstructor().setInfo(
            Type.MethodType(Symbol.EMPTY_ARRAY, clasz.typeConstructor()));
    }

    /** Initializes the given type alias */
    private void initAlias(Symbol alias, Type aliased) {
        alias.setInfo(aliased);
        alias.primaryConstructor().setInfo(
            Type.MethodType(Symbol.EMPTY_ARRAY, aliased));
    }

    /** Initializes the given method */
    private void initMethod(Symbol method, Type[] vargs, Type result) {
        Symbol[] vparams = new Symbol[vargs.length];
        for (int i = 0; i < vargs.length; i++)
            vparams[i] = newVParam(method, i, vargs[i]);
        method.setInfo(Type.MethodType(vparams, result));
    }

    /** Returns the term member of given class with given name. */
    private Symbol loadTerm(Symbol clasz, Name name) {
        Symbol sym = clasz.lookup(name);
        assert sym.isTerm() && !sym.isOverloaded(): clasz+"."+name+" -> "+sym;
        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 });
    }

    /** Returns the type of given class applied to given type arguments. */
    private Type getType(Symbol clasz, Type[] args) {
        return Type.appliedType(clasz.type(), args);
    }

    //########################################################################
}