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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2004, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
** **
** $Id$
\* */
package scalac.symtab;
import scala.tools.util.Position;
import scalac.Global;
import scalac.atree.ATreeTyper;
import scalac.util.Debug;
import scalac.util.Name;
import scalac.util.Names;
public class Definitions {
//########################################################################
// Public Fields - Root module
/** The attributed tree typer */
public final ATreeTyper atyper;
//########################################################################
// Public Fields & Methods - Root class and some standard packages
/** The root class */
public final Symbol ROOT_CLASS;
/** The java package */
public final Symbol JAVA;
/** The java.lang package */
public final Symbol JAVALANG;
/** The scala package */
public final Symbol SCALA;
//########################################################################
// Public Fields & Methods - Top and bottom classes
/** The scala.Any class */
public final Symbol ANY_CLASS;
public final Type ANY_TYPE() {return ANY_CLASS.staticType();}
/** The scala.AnyVal class */
public final Symbol ANYVAL_CLASS;
public final Type ANYVAL_TYPE() {return ANYVAL_CLASS.staticType();}
/** The scala.AnyRef class */
public final Symbol ANYREF_CLASS;
public final Type ANYREF_TYPE() {return ANYREF_CLASS.staticType();}
/** The scala.AllRef class */
public final Symbol ALLREF_CLASS;
public final Type ALLREF_TYPE() {return ALLREF_CLASS.staticType();}
/** The scala.All class */
public final Symbol ALL_CLASS;
public final Type ALL_TYPE() {return ALL_CLASS.staticType();}
//########################################################################
// Public Fields & Methods - Java classes
/** The java.lang.Object class */
public final Symbol OBJECT_CLASS;
public final Type OBJECT_TYPE() {return OBJECT_CLASS.staticType();}
/** The java.lang.String class */
public final Symbol STRING_CLASS;
public final Type STRING_TYPE() {return STRING_CLASS.staticType();}
/** The java.lang.Throwable class */
public final Symbol THROWABLE_CLASS;
public final Type THROWABLE_TYPE() {return THROWABLE_CLASS.staticType();}
/** The java.io.Serializable class */
public final Symbol SERIALIZABLE_CLASS;
public final Type SERIALIZABLE_TYPE() {return SERIALIZABLE_CLASS.staticType();}
//########################################################################
// Public Fields & Methods - Scala value classes
/** The scala.Unit class */
public final Symbol UNIT_CLASS;
public final Type UNIT_TYPE() {return UNIT_CLASS.staticType();}
/** The scala.Boolean class */
public final Symbol BOOLEAN_CLASS;
public final Type BOOLEAN_TYPE() {return BOOLEAN_CLASS.staticType();}
/** The scala.Byte class */
public final Symbol BYTE_CLASS;
public final Type BYTE_TYPE() {return BYTE_CLASS.staticType();}
/** The scala.Short class */
public final Symbol SHORT_CLASS;
public final Type SHORT_TYPE() {return SHORT_CLASS.staticType();}
/** The scala.Char class */
public final Symbol CHAR_CLASS;
public final Type CHAR_TYPE() {return CHAR_CLASS.staticType();}
/** The scala.Int class */
public final Symbol INT_CLASS;
public final Type INT_TYPE() {return INT_CLASS.staticType();}
/** The scala.Long class */
public final Symbol LONG_CLASS;
public final Type LONG_TYPE() {return LONG_CLASS.staticType();}
/** The scala.Float class */
public final Symbol FLOAT_CLASS;
public final Type FLOAT_TYPE() {return FLOAT_CLASS.staticType();}
/** The scala.Double class */
public final Symbol DOUBLE_CLASS;
public final Type DOUBLE_TYPE() {return DOUBLE_CLASS.staticType();}
//########################################################################
// Public Fields & Methods - Scala reference classes
/** The scala.ScalaObject class */
public final Symbol SCALAOBJECT_CLASS;
public final Type SCALAOBJECT_TYPE() {return SCALAOBJECT_CLASS.staticType();}
/** The scala.Attribute class */
public final Symbol ATTRIBUTE_CLASS;
public final Type ATTRIBUTE_TYPE() {return ATTRIBUTE_CLASS.staticType();}
/** The scala.Ref class */
public final Symbol REF_CLASS;
public final Type REF_TYPE(Type element) {
return REF_CLASS.staticType(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 TUPLE_CLASS[args.length].staticType(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 FUNCTION_CLASS[args.length - 1].staticType(args);
}
/** The scala.PartialFunction class */
public final Symbol PARTIALFUNCTION_CLASS;
public final Type PARTIALFUNCTION_TYPE(Type argument, Type result) {
return PARTIALFUNCTION_CLASS.staticType(argument, result);
}
/** The scala.Iterable class */
public final Symbol ITERABLE_CLASS;
public final Type ITERABLE_TYPE(Type element) {
return ITERABLE_CLASS.staticType(element);
}
/** The scala.Iterator class */
public final Symbol ITERATOR_CLASS;
public final Type ITERATOR_TYPE(Type element) {
return ITERATOR_CLASS.staticType(element);
}
/** The scala.Seq class */
public final Symbol SEQ_CLASS;
public final Type SEQ_TYPE(Type element) {
return SEQ_CLASS.staticType(element);
}
/** The scala.List class */
public final Symbol LIST_CLASS;
public final Type LIST_TYPE(Type element) {
return LIST_CLASS.staticType(element);
}
/** The scala.Nil module
* evaluated on demand to make bootstrap possible.
*/
public final Symbol NIL() {
return getModule("scala.Nil");
}
/** The scala.:: class
* evaluated on demand to make bootstrap possible.
*/
public final Symbol CONS_CLASS() {
return getClass("scala.$colon$colon");
}
public final Type CONS_TYPE(Type element) {
return CONS_CLASS().staticType(element);
}
/** The scala.Array class */
public final Symbol ARRAY_CLASS;
public final Type ARRAY_TYPE(Type element) {
return ARRAY_CLASS.staticType(element);
}
/** The scala.Type class & its subclasses */
public final Symbol TYPE_CLASS;
public final Type TYPE_TYPE() {
return TYPE_CLASS.staticType();
}
public final Symbol CLASSTYPE_CLASS;
public final Type CLASSTYPE_TYPE() {
return CLASSTYPE_CLASS.staticType();
}
public final Symbol JAVACLASSTYPE_CLASS;
public final Symbol JAVAREFARRAYTYPE_CLASS;
public final Symbol SCALACLASSTYPE_CLASS;
public final Type SCALACLASSTYPE_TYPE() {
return SCALACLASSTYPE_CLASS.staticType();
}
public final Symbol SINGLETYPE_CLASS;
public final Symbol TYPECONSTRUCTOR_CLASS;
public final Type TYPECONSTRUCTOR_TYPE() {
return TYPECONSTRUCTOR_CLASS.staticType();
}
public final Symbol COMPOUNDTYPE_CLASS;
/** 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 - Scala primitive types
/** Returns the primitive type void. */
public final Type void_TYPE() {
return void_TYPE.type().resultType();
}
/** Returns the primitive type boolean. */
public final Type boolean_TYPE() {
return boolean_TYPE.type().resultType();
}
/** Returns the primitive type byte. */
public final Type byte_TYPE() {
return byte_TYPE.type().resultType();
}
/** Returns the primitive type short. */
public final Type short_TYPE() {
return short_TYPE.type().resultType();
}
/** Returns the primitive type char. */
public final Type char_TYPE() {
return char_TYPE.type().resultType();
}
/** Returns the primitive type int. */
public final Type int_TYPE() {
return int_TYPE.type().resultType();
}
/** Returns the primitive type long. */
public final Type long_TYPE() {
return long_TYPE.type().resultType();
}
/** Returns the primitive type float. */
public final Type float_TYPE() {
return float_TYPE.type().resultType();
}
/** Returns the primitive type double. */
public final Type double_TYPE() {
return double_TYPE.type().resultType();
}
/** Returns the primitive array type of given element type. */
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);
}
}
//########################################################################
// Public Fields & Methods - Top and bottom class methods
/** Some scala.Any methods */
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_IS_ERASED;
public final Symbol ANY_AS;
public final Symbol ANY_AS_ERASED;
public final Symbol ANY_MATCH;
//########################################################################
// Public Fields & Methods - Java class methods
/** Some java.lang.Object methods */
public final Symbol OBJECT_EQ;
public final Symbol OBJECT_SYNCHRONIZED;
/** Some java.lang.String methods */
public final Symbol STRING_PLUS;
/** Some java.lang.Throwable methods */
public final Symbol 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.ScalaObject methods */
private Symbol SCALAOBJECT_TAG;
public Symbol SCALAOBJECT_TAG() {
if (SCALAOBJECT_TAG == null)
SCALAOBJECT_TAG = loadTerm(SCALAOBJECT_CLASS, Names.tag);
return SCALAOBJECT_TAG;
}
private Symbol SCALAOBJECT_GETTYPE;
public Symbol SCALAOBJECT_GETTYPE() {
if (SCALAOBJECT_GETTYPE == null)
SCALAOBJECT_GETTYPE = loadTerm(SCALAOBJECT_CLASS, Names.getType);
return SCALAOBJECT_GETTYPE;
}
/** 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 = PREDEF.lookup(Names.Array).firstAlternative();
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;
}
private Symbol MATCHERROR_REPORT;
public Symbol MATCHERROR_REPORT() {
if (MATCHERROR_REPORT == null)
MATCHERROR_REPORT = loadTerm(MATCHERROR, Names.report);
return MATCHERROR_REPORT;
}
/** The scala.Type class (and subclasses) */
private Symbol TYPE_DEFAULTVALUE;
public Symbol TYPE_DEFAULTVALUE() {
if (TYPE_DEFAULTVALUE == null)
TYPE_DEFAULTVALUE = loadTerm(TYPE_CLASS, Names.defaultValue);
return TYPE_DEFAULTVALUE;
}
private Symbol TYPE_NEWARRAY;
public Symbol TYPE_NEWARRAY() {
if (TYPE_NEWARRAY == null)
TYPE_NEWARRAY = loadTerm(TYPE_CLASS, Names.newArray);
return TYPE_NEWARRAY;
}
private Symbol TYPE_ISINSTANCE;
public Symbol TYPE_ISINSTANCE() {
if (TYPE_ISINSTANCE == null)
TYPE_ISINSTANCE = loadTerm(TYPE_CLASS, Names.isInstance);
assert TYPE_ISINSTANCE != Symbol.NONE;
return TYPE_ISINSTANCE;
}
private Symbol TYPE_CAST;
public Symbol TYPE_CAST() {
if (TYPE_CAST == null)
TYPE_CAST = loadTerm(TYPE_CLASS, Names.cast);
return TYPE_CAST;
}
private Symbol RTT_DOUBLE;
public Symbol RTT_DOUBLE() {
if (RTT_DOUBLE == null)
RTT_DOUBLE = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Double);
return RTT_DOUBLE;
}
private Symbol RTT_FLOAT;
public Symbol RTT_FLOAT() {
if (RTT_FLOAT == null)
RTT_FLOAT = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Float);
return RTT_FLOAT;
}
private Symbol RTT_LONG;
public Symbol RTT_LONG() {
if (RTT_LONG == null)
RTT_LONG = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Long);
return RTT_LONG;
}
private Symbol RTT_INT;
public Symbol RTT_INT() {
if (RTT_INT == null)
RTT_INT = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Int);
return RTT_INT;
}
private Symbol RTT_SHORT;
public Symbol RTT_SHORT() {
if (RTT_SHORT == null)
RTT_SHORT = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Short);
return RTT_SHORT;
}
private Symbol RTT_CHAR;
public Symbol RTT_CHAR() {
if (RTT_CHAR == null)
RTT_CHAR = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Char);
return RTT_CHAR;
}
private Symbol RTT_BYTE;
public Symbol RTT_BYTE() {
if (RTT_BYTE == null)
RTT_BYTE = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Byte);
return RTT_BYTE;
}
private Symbol RTT_BOOLEAN;
public Symbol RTT_BOOLEAN() {
if (RTT_BOOLEAN == null)
RTT_BOOLEAN = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Boolean);
return RTT_BOOLEAN;
}
private Symbol RTT_UNIT;
public Symbol RTT_UNIT() {
if (RTT_UNIT == null)
RTT_UNIT = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Unit);
return RTT_UNIT;
}
private Symbol RTT_ANY;
public Symbol RTT_ANY() {
if (RTT_ANY == null)
RTT_ANY = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.Any);
return RTT_ANY;
}
private Symbol RTT_ANYVAL;
public Symbol RTT_ANYVAL() {
if (RTT_ANYVAL == null)
RTT_ANYVAL = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.AnyVal);
return RTT_ANYVAL;
}
private Symbol RTT_ALLREF;
public Symbol RTT_ALLREF() {
if (RTT_ALLREF == null)
RTT_ALLREF = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.AllRef);
return RTT_ALLREF;
}
private Symbol RTT_ALL;
public Symbol RTT_ALL() {
if (RTT_ALL == null)
RTT_ALL = loadTerm(TYPE_CLASS.linkedModule().moduleClass(), Names.All);
return RTT_ALL;
}
private Symbol TYPECONSTRUCTOR_GETINSTANTIATION;
public Symbol TYPECONSTRUCTOR_GETINSTANTIATION() {
if (TYPECONSTRUCTOR_GETINSTANTIATION == null) {
TYPECONSTRUCTOR_GETINSTANTIATION =
loadTerm(TYPECONSTRUCTOR_CLASS, Names.getInstantiation);
}
return TYPECONSTRUCTOR_GETINSTANTIATION;
}
private Symbol TYPECONSTRUCTOR_INSTANTIATE;
public Symbol TYPECONSTRUCTOR_INSTANTIATE() {
if (TYPECONSTRUCTOR_INSTANTIATE == null)
TYPECONSTRUCTOR_INSTANTIATE =
loadTerm(TYPECONSTRUCTOR_CLASS, Names.instantiate);
return TYPECONSTRUCTOR_INSTANTIATE;
}
private Symbol TYPECONSTRUCTOR_FUNCTIONOUTER;
public Symbol TYPECONSTRUCTOR_FUNCTIONOUTER() {
if (TYPECONSTRUCTOR_FUNCTIONOUTER == null)
TYPECONSTRUCTOR_FUNCTIONOUTER =
loadTerm(TYPECONSTRUCTOR_CLASS.linkedModule().moduleClass(), Names.functionOuter);
return TYPECONSTRUCTOR_FUNCTIONOUTER;
}
private Symbol SCALACLASSTYPE_WEAKISINSTANCE;
public Symbol SCALACLASSTYPE_WEAKISINSTANCE() {
if (SCALACLASSTYPE_WEAKISINSTANCE == null)
SCALACLASSTYPE_WEAKISINSTANCE =
loadTerm(SCALACLASSTYPE_CLASS, Names.weakIsInstance);
return SCALACLASSTYPE_WEAKISINSTANCE;
}
private Symbol SCALACLASSTYPE_SETPARENTS;
public Symbol SCALACLASSTYPE_SETPARENTS() {
if (SCALACLASSTYPE_SETPARENTS == null)
SCALACLASSTYPE_SETPARENTS =
loadTerm(SCALACLASSTYPE_CLASS, Names.setParents);
return SCALACLASSTYPE_SETPARENTS;
}
private Symbol SCALACLASSTYPE_EMPTYARRAY;
public Symbol SCALACLASSTYPE_EMPTYARRAY() {
if (SCALACLASSTYPE_EMPTYARRAY == null)
SCALACLASSTYPE_EMPTYARRAY =
loadTerm(SCALACLASSTYPE_CLASS.linkedModule().moduleClass(),
Names.emptyArray);
return SCALACLASSTYPE_EMPTYARRAY;
}
private Symbol JAVACLASSTYPE_JAVACLASSTYPE;
public Symbol JAVACLASSTYPE_JAVACLASSTYPE() {
if (JAVACLASSTYPE_JAVACLASSTYPE == null)
JAVACLASSTYPE_JAVACLASSTYPE =
loadTerm(JAVACLASSTYPE_CLASS.linkedModule().moduleClass(),
Names.javaClassType);
return JAVACLASSTYPE_JAVACLASSTYPE;
}
//########################################################################
// Public Fields - Global values
/** The universal pattern */
public final Symbol PATTERN_WILDCARD;
//########################################################################
// Private Fields - Symbol
private final Symbol void_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;
// create attributed tree typer
atyper = new ATreeTyper(global, this);
// the root class
ROOT_CLASS = ClassSymbol.newRootClass(global);
// the java, java.lang and scala packages
JAVA = getModule("java");
JAVALANG = getModule("java.lang");
SCALA = getModule("scala");
// the top and bottom classes
Symbol SCALA_CLASS = SCALA.moduleClass();
ANY_CLASS = newClass(SCALA_CLASS, Names.Any, 0);
ANYVAL_CLASS = getClass("scala.AnyVal");
ANYREF_CLASS = newAlias(SCALA_CLASS, Names.AnyRef, 0);
ALLREF_CLASS = newClass(SCALA_CLASS, Names.AllRef, Modifiers.ABSTRACT | Modifiers.FINAL);
ALL_CLASS = newClass(SCALA_CLASS, Names.All, Modifiers.ABSTRACT | Modifiers.FINAL);
final boolean forMSIL = global.target == Global.TARGET_MSIL;
// the java classes
OBJECT_CLASS = getClass(forMSIL ? "System.Object" : "java.lang.Object");
STRING_CLASS = getClass(forMSIL ? "System.String" : "java.lang.String");
THROWABLE_CLASS =
getClass(forMSIL ? "System.Exception" : "java.lang.Throwable");
SERIALIZABLE_CLASS = getClass("java.io.Serializable");
// the scala value classes
UNIT_CLASS = getClass("scala.Unit");
BOOLEAN_CLASS = getClass("scala.Boolean");
BYTE_CLASS = getClass("scala.Byte");
SHORT_CLASS = getClass("scala.Short");
CHAR_CLASS = getClass("scala.Char");
INT_CLASS = getClass("scala.Int");
LONG_CLASS = getClass("scala.Long");
FLOAT_CLASS = getClass("scala.Float");
DOUBLE_CLASS = getClass("scala.Double");
// the scala reference classes
SCALAOBJECT_CLASS = getClass("scala.ScalaObject");
ATTRIBUTE_CLASS = getClass("scala.Attribute");
REF_CLASS = getClass("scala.Ref");
for (int i = 1; i < TUPLE_COUNT; i++) {
TUPLE_CLASS[i] = getClass("scala.Tuple" + i);
TUPLE_FIELD[i] = new Symbol[i];
}
for (int i = 0; i < FUNCTION_COUNT; i++)
FUNCTION_CLASS[i] = getClass("scala.Function" + i);
PARTIALFUNCTION_CLASS = getClass("scala.PartialFunction");
ITERABLE_CLASS = getClass("scala.Iterable");
ITERATOR_CLASS = getClass("scala.Iterator");
SEQ_CLASS = getClass("scala.Seq");
LIST_CLASS = getClass("scala.List");
ARRAY_CLASS = getClass("scala.Array");
TYPE_CLASS = getJVMClass("scala.Type");
CLASSTYPE_CLASS = getJVMClass("scala.runtime.types.ClassType");
JAVACLASSTYPE_CLASS = getJVMClass("scala.runtime.types.JavaClassType");
JAVAREFARRAYTYPE_CLASS = getJVMClass("scala.runtime.types.JavaRefArrayType");
SCALACLASSTYPE_CLASS = getJVMClass("scala.runtime.types.ScalaClassType");
SINGLETYPE_CLASS = getJVMClass("scala.runtime.types.SingleType");
TYPECONSTRUCTOR_CLASS = getJVMClass("scala.runtime.types.TypeConstructor");
COMPOUNDTYPE_CLASS = getJVMClass("scala.runtime.types.CompoundType");
PREDEF = getModule("scala.Predef");
CONSOLE = getModule("scala.Console");
MATCHERROR = getModule("scala.MatchError");
// initialize generated classes and aliases
initClass(ANY_CLASS, Type.EMPTY_ARRAY);
initAlias(ANYREF_CLASS, OBJECT_TYPE());
initClass(ALLREF_CLASS, new Type[]{ANYREF_TYPE()});
initClass(ALL_CLASS, new Type[]{ANY_TYPE()});
// create type symbols
void_TYPE = newTypeMethod(Names.Unit ,UNIT_TYPE());
boolean_TYPE = newTypeMethod(Names.Boolean,BOOLEAN_TYPE());
byte_TYPE = newTypeMethod(Names.Byte ,BYTE_TYPE());
short_TYPE = newTypeMethod(Names.Short ,SHORT_TYPE());
char_TYPE = newTypeMethod(Names.Char ,CHAR_TYPE());
int_TYPE = newTypeMethod(Names.Int ,INT_TYPE());
long_TYPE = newTypeMethod(Names.Long ,LONG_TYPE());
float_TYPE = newTypeMethod(Names.Float ,FLOAT_TYPE());
double_TYPE = newTypeMethod(Names.Double ,DOUBLE_TYPE());
array_TYPE = newTypeMethod(Names.Array ,ARRAY_TYPE(ANYREF_TYPE()));
// add members to scala.Any
ANY_EQEQ = newMethod(ANY_CLASS,Names.EQEQ ,Modifiers.FINAL);
ANY_BANGEQ = newMethod(ANY_CLASS,Names.BANGEQ ,Modifiers.FINAL);
ANY_EQUALS = newMethod(ANY_CLASS,Names.equals ,0);
ANY_HASHCODE = newMethod(ANY_CLASS,Names.hashCode ,0);
ANY_TOSTRING = newMethod(ANY_CLASS,Names.toString ,0);
// ANY_PLUS = newMethod(ANY_CLASS,Names.PLUS ,Modifiers.FINAL);
ANY_IS = newMethod(ANY_CLASS,Names.isInstanceOf,Modifiers.FINAL);
ANY_IS_ERASED= newMethod(ANY_CLASS,Names.isInstanceOfE,Modifiers.FINAL);
ANY_AS = newMethod(ANY_CLASS,Names.asInstanceOf,Modifiers.FINAL);
ANY_AS_ERASED= newMethod(ANY_CLASS,Names.asInstanceOfE,Modifiers.FINAL);
ANY_MATCH = newMethod(ANY_CLASS,Names._match ,Modifiers.FINAL);
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_IS_ERASED_TPARAMS =
{newTParam(ANY_IS_ERASED, 0, ANY_TYPE())};
ANY_IS_ERASED.setInfo(Type.PolyType(ANY_IS_ERASED_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_AS_ERASED_TPARAMS =
{newTParam(ANY_AS_ERASED, 0, ANY_TYPE())};
ANY_AS_ERASED.setInfo(Type.PolyType(ANY_AS_ERASED_TPARAMS,
ANY_AS_ERASED_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 java.lang.Object
OBJECT_EQ =
newMethod(OBJECT_CLASS, Names.eq, Modifiers.FINAL);
OBJECT_SYNCHRONIZED =
newMethod(OBJECT_CLASS, Names.synchronized_, Modifiers.FINAL);
initMethod(OBJECT_EQ, new Type[]{ANYREF_TYPE()}, boolean_TYPE());
Symbol OBJECT_SYNCHRONIZED_TPARAM =
newTParam(OBJECT_SYNCHRONIZED,0,ANY_TYPE());
Symbol OBJECT_SYNCHRONIZED_VPARAM =
newVParam(OBJECT_SYNCHRONIZED,0,OBJECT_SYNCHRONIZED_TPARAM.type());
OBJECT_SYNCHRONIZED.setInfo(
Type.PolyType(
new Symbol[] {OBJECT_SYNCHRONIZED_TPARAM},
Type.MethodType(
new Symbol[] {OBJECT_SYNCHRONIZED_VPARAM},
OBJECT_SYNCHRONIZED_TPARAM.type())));
if (forMSIL) {
Symbol WAIT0 = newMethod(OBJECT_CLASS, Names.wait, Modifiers.FINAL);
initMethod(WAIT0, Type.EMPTY_ARRAY, UNIT_TYPE());
Symbol WAIT1 = newMethod(OBJECT_CLASS, Names.wait, Modifiers.FINAL);
initMethod(WAIT1, new Type[]{LONG_TYPE()}, UNIT_TYPE());
Symbol WAIT2 = newMethod(OBJECT_CLASS, Names.wait, Modifiers.FINAL);
initMethod(WAIT2, new Type[]{LONG_TYPE(), INT_TYPE()}, UNIT_TYPE());
Symbol NOTIFY =
newMethod(OBJECT_CLASS, Names.notify, Modifiers.FINAL);
initMethod(NOTIFY, Type.EMPTY_ARRAY, UNIT_TYPE());
Symbol NOTIFY_ALL =
newMethod(OBJECT_CLASS, Names.notifyAll, Modifiers.FINAL);
initMethod(NOTIFY_ALL, Type.EMPTY_ARRAY, UNIT_TYPE());
Symbol JLOA = newAlias(JAVALANG, Names.Object, 0);
initAlias(JLOA, OBJECT_TYPE());
}
// add members to java.lang.String
STRING_PLUS = newMethod(STRING_CLASS, Names.PLUS, Modifiers.FINAL);
initMethod(STRING_PLUS, new Type[]{ANY_TYPE()}, STRING_TYPE());
if (forMSIL) {
Symbol s = newMethod(STRING_CLASS, Name.fromString("length"), 0);
initMethod(s, Type.EMPTY_ARRAY, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("compareTo"), 0);
initMethod(s, new Type[] {STRING_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("charAt"), 0);
initMethod(s, new Type[] {INT_TYPE()}, CHAR_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("concat"), 0);
initMethod(s, new Type[] {STRING_TYPE()}, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("indexOf"), 0);
initMethod(s, new Type[] {INT_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("indexOf"), 0);
initMethod(s, new Type[] {INT_TYPE(), INT_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("indexOf"), 0);
initMethod(s, new Type[] {STRING_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("indexOf"), 0);
initMethod(s, new Type[] {STRING_TYPE(), INT_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("lastIndexOf"), 0);
initMethod(s, new Type[] {INT_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("lastIndexOf"), 0);
initMethod(s, new Type[] {INT_TYPE(), INT_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("lastIndexOf"), 0);
initMethod(s, new Type[] {STRING_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("lastIndexOf"), 0);
initMethod(s, new Type[] {STRING_TYPE(), INT_TYPE()}, INT_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("toLowerCase"), 0);
initMethod(s, Type.EMPTY_ARRAY, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("toUpperCase"), 0);
initMethod(s, Type.EMPTY_ARRAY, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("startsWith"), 0);
initMethod(s, new Type[]{STRING_TYPE()}, BOOLEAN_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("endsWith"), 0);
initMethod(s, new Type[]{STRING_TYPE()}, BOOLEAN_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("substring"), 0);
initMethod(s, new Type[]{INT_TYPE()}, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("substring"), 0);
initMethod(s, new Type[]{INT_TYPE(), INT_TYPE()}, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("intern"), 0);
initMethod(s, Type.EMPTY_ARRAY, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("replace"), 0);
initMethod(s, new Type[]{CHAR_TYPE(), CHAR_TYPE()}, STRING_TYPE());
s = newMethod(STRING_CLASS, Name.fromString("toCharArray"), 0);
initMethod(s, Type.EMPTY_ARRAY, array_TYPE(CHAR_TYPE()));
Symbol JLSA = newAlias(JAVALANG, Names.String, 0);
initAlias(JLSA, STRING_TYPE());
}
// add members to java.lang.Throwable
THROWABLE_THROW =
newMethod(THROWABLE_CLASS, Names.throw_, Modifiers.FINAL);
THROWABLE_THROW.setInfo(Type.PolyType(Symbol.EMPTY_ARRAY, ALL_TYPE()));
// create global values
PATTERN_WILDCARD = Symbol.NONE.newTerm(
Position.NOPOS, 0, Names.PATTERN_WILDCARD);
PATTERN_WILDCARD.setInfo(ALL_TYPE());
// initialize unboxed types in class Type
Type.initializeUnboxedTypes(this);
}
//########################################################################
// Public Methods
/** Returns the symbol of the module with the given fullname. */
public Symbol getModule(String fullname) {
Scope scope = ROOT_CLASS.members();
int i = 0;
int j = fullname.indexOf('.', i);
while (j >= 0) {
Name name = Name.fromString(fullname.substring(i, j));
scope = scope.lookup(name).members();
i = j + 1;
j = fullname.indexOf('.', i);
}
Name name = Name.fromString(fullname.substring(i, fullname.length()));
Symbol sym = scope.lookup(name);
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;
}
}
return sym;
}
/** Returns the symbol of the class with the given fullname. */
public Symbol getClass(String fullname) {
Scope scope = ROOT_CLASS.members();
int i = 0;
int j = fullname.indexOf('.', i);
while (j >= 0) {
Name name = Name.fromString(fullname.substring(i, j));
scope = scope.lookup(name).members();
i = j + 1;
j = fullname.indexOf('.', i);
}
Name name = Name.fromString(fullname.substring(i, fullname.length()));
Symbol sym = scope.lookup(name.toTypeName());
assert sym.kind != Kinds.NONE : "no class '" + fullname + "'";
return sym;
}
private Symbol getJVMClass(String fullname) {
return Global.instance.target == Global.TARGET_MSIL ? null :
getClass(fullname);
}
//########################################################################
// Private Methods
/** Creates a new class */
private Symbol newClass(Symbol owner, Name name, int flags) {
name = name.toTypeName();
Symbol clasz = owner.newClass(Position.NOPOS, flags, name);
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 = owner.newTypeAlias(Position.NOPOS, flags, name);
owner.members().enter(alias);
return alias;
}
/** Creates a new method */
private Symbol newMethod(Symbol owner, Name name, int flags) {
assert owner.isClassType(): Debug.show(owner) + " -- " + name;
Symbol term = owner.newMethod(Position.NOPOS, flags, name);
owner.members().enterOrOverload(term);
return term;
}
/** Creates a new type parameter */
private Symbol newTParam(Symbol owner, int index, Type bound) {
Name name = Name.fromString("T" + index).toTypeName();
return owner.newTParam(Position.NOPOS, 0, name, bound);
}
/** Creates a new value parameter */
private Symbol newVParam(Symbol owner, int index, Type type) {
Name name = Name.fromString("v" + index);
return owner.newVParam(Position.NOPOS, 0, name, type);
}
/** Creates a new type method */
private Symbol newTypeMethod(Name name, Type type) {
Symbol symbol = ANY_CLASS.newMethod(Position.NOPOS, 0, name);
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(): clasz+"."+name+" -> "+sym;
assert !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));
}
//########################################################################
}
|