summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/Symbol.java
blob: 45c3b05548b56b4c9c3a834c128b995322d047a8 (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
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
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
**

\*                                                                      */

//todo check significance of JAVA flag.

package scalac.symtab;

import scala.tools.util.Position;

import scalac.ApplicationError;
import scalac.Global;
import scalac.Phase;
import scalac.framework.History;
import scalac.util.ArrayApply;
import scalac.util.Name;
import scalac.util.Names;
import scalac.util.NameTransformer;
import scalac.util.Debug;


public abstract class Symbol implements Modifiers, Kinds {

    /** An empty symbol array */
    public static final Symbol[] EMPTY_ARRAY = new Symbol[0];

    /** An empty array of symbol arrays */
    public static final Symbol[][] EMPTY_ARRAY_ARRAY = new Symbol[0][];

    /** The absent symbol */
    public static final Symbol NONE = new NoSymbol();

// Attribues -------------------------------------------------------------

    public static final int IS_ROOT         = 0x00000001;
    public static final int IS_ANONYMOUS    = 0x00000002;
    public static final int IS_LABEL        = 0x00000010;
    public static final int IS_CONSTRUCTOR  = 0x00000020;
    public static final int IS_ACCESSMETHOD = 0x00000100;
    public static final int IS_ERROR        = 0x10000000;
    public static final int IS_THISTYPE     = 0x20000000;
    public static final int IS_LOCALDUMMY   = 0x40000000;
    public static final int IS_COMPOUND     = 0x80000000;

// Fields -------------------------------------------------------------

    /** The unique identifier generator */
    private static int ids;

    /** The kind of the symbol */
    public int kind;

    /** The position of the symbol */
    public int pos;

    /** The name of the symbol */
    public Name name;

    /** The modifiers of the symbol */
    public int flags;

    /** The owner of the symbol */
    private Symbol owner;

    /** The infos of the symbol */
    private TypeIntervalList infos;

    /** The attributes of the symbol */
    private final int attrs;

    /** The unique identifier */
    public final int id;


// Constructors -----------------------------------------------------------

    /** Generic symbol constructor */
    public Symbol(int kind, Symbol owner, int pos, int flags, Name name, int attrs) {
        this.kind = kind;
        this.pos = pos;
        this.name = name;
        this.owner = owner == null ? this : owner;
        this.flags = flags & ~(INITIALIZED | LOCKED); // safety first
        this.attrs = attrs;
        this.id = ids++;
    }

// Factories --------------------------------------------------------------

    /** Creates a new term owned by this symbol. */
    public final Symbol newTerm(int pos, int flags, Name name) {
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new constructor of this symbol. */
    public final Symbol newConstructor(int pos, int flags) {
        assert isType(): Debug.show(this);
        return new ConstructorSymbol(this, pos, flags);
    }

    /** Creates a new method owned by this symbol. */
    public final Symbol newMethod(int pos, int flags, Name name) {
        assert isClass(): Debug.show(this);
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new access method owned by this symbol. */
    public final Symbol newAccessMethod(int pos, Name name) {
        assert isClass(): Debug.show(this);
        int flags = PRIVATE | FINAL | SYNTHETIC;
        return newTerm(pos, flags, name, IS_ACCESSMETHOD);
    }

    /** Creates a new function owned by this symbol. */
    public final Symbol newFunction(int pos, int flags, Name name) {
        assert isTerm(): Debug.show(this);
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new method or function owned by this symbol. */
    public final Symbol newMethodOrFunction(int pos, int flags, Name name){
        assert isClass() || isTerm(): Debug.show(this);
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new label owned by this symbol. */
    public final Symbol newLabel(int pos, Name name) {
        assert isTerm(): Debug.show(this);
        return newTerm(pos, 0, name, IS_LABEL);
    }

    /** Creates a new field owned by this symbol. */
    public final Symbol newField(int pos, int flags, Name name) {
        assert isClass(): Debug.show(this);
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new variable owned by this symbol. */
    public final Symbol newVariable(int pos, int flags, Name name) {
        assert isTerm(): Debug.show(this);
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new variable owned by this symbol. */
    public final Symbol newFieldOrVariable(int pos, int flags, Name name) {
        assert isClass() || isTerm(): Debug.show(this);
        return newTerm(pos, flags, name, 0);
    }

    /** Creates a new pattern variable owned by this symbol. */
    public final Symbol newPatternVariable(int pos, Name name) {
        return newVariable(pos, 0, name);
    }

    /** Creates a new value parameter owned by this symbol. */
    public final Symbol newVParam(int pos, int flags, Name name) {
        assert isTerm(): Debug.show(this);
        return newTerm(pos, flags | PARAM, name);
    }

    /**
     * Creates a new value parameter owned by this symbol and
     * initializes it with the type.
     */
    public final Symbol newVParam(int pos, int flags, Name name, Type type) {
        Symbol tparam = newVParam(pos, flags, name);
        tparam.setInfo(type);
        return tparam;
    }

    /**
     * Creates a new initialized dummy symbol for template of this
     * class.
     */
    public final Symbol newLocalDummy() {
        assert isClass(): Debug.show(this);
        Symbol local = newTerm(pos, 0, Names.LOCAL(this), IS_LOCALDUMMY);
        local.setInfo(Type.NoType);
        return local;
    }

    /** Creates a new module owned by this symbol. */
    public final Symbol newModule(int pos, int flags, Name name) {
        return new ModuleSymbol(this, pos, flags, name);
    }

    /**
     * Creates a new package owned by this symbol and initializes it
     * with an empty scope.
     */
    public final Symbol newPackage(int pos, Name name) {
        return newPackage(pos, name, null);
    }

    /**
     * Creates a new package owned by this symbol, initializes it with
     * the loader and enters it in the scope if it's non-null.
     */
    public final Symbol newLoadedPackage(Name name, SymbolLoader loader,
        Scope scope)
    {
        assert loader != null: Debug.show(this) + " - " + name;
        Symbol peckage = newPackage(Position.NOPOS, name, loader);
        if (scope != null) scope.enterNoHide(peckage);
        return peckage;
    }

    /**
     * Creates a new error value owned by this symbol and initializes
     * it with an error type.
     */
    public Symbol newErrorValue(Name name) {
        Symbol symbol = newTerm(pos, SYNTHETIC, name, IS_ERROR);
        symbol.setInfo(Type.ErrorType);
        return symbol;
    }

    /** Creates a new type alias owned by this symbol. */
    public final Symbol newTypeAlias(int pos, int flags, Name name) {
        return new AliasTypeSymbol(this, pos, flags, name, 0);
    }

    /** Creates a new abstract type owned by this symbol. */
    public final Symbol newAbstractType(int pos, int flags, Name name) {
        return new AbsTypeSymbol(this, pos, flags, name, 0);
    }

    /** Creates a new type parameter owned by this symbol. */
    public final Symbol newTParam(int pos, int flags, Name name) {
        assert isTerm(): Debug.show(this);
        return newAbstractType(pos, flags | PARAM, name);
    }

    /**
     * Creates a new type parameter owned by this symbol and
     * initializes it with the type.
     */
    public final Symbol newTParam(int pos, int flags, Name name, Type type) {
        Symbol tparam = newTParam(pos, flags, name);
        tparam.setInfo(type);
        return tparam;
    }

    /**
     * Creates a new type alias owned by this symbol and initializes
     * it with the info.
     */
    public final Symbol newTypeAlias(int pos, int flags, Name name, Type info){
        Symbol alias = newTypeAlias(pos, flags, name);
        alias.setInfo(info);
        alias.allConstructors().setInfo(Type.MethodType(EMPTY_ARRAY, info));
        return alias;
    }

    /** Creates a new class owned by this symbol. */
    public final ClassSymbol newClass(int pos, int flags, Name name) {
        return newClass(pos, flags, name, 0);
    }

    /** Creates a new anonymous class owned by this symbol. */
    public final ClassSymbol newAnonymousClass(int pos, Name name) {
        assert isTerm(): Debug.show(this);
        return newClass(pos, 0, name, IS_ANONYMOUS);
    }

    /**
     * Creates a new class with a linked module, both owned by this
     * symbol, initializes them with the loader and enters the class
     * and the module in the scope if it's non-null.
     */
    public final ClassSymbol newLoadedClass(int flags, Name name,
        SymbolLoader loader, Scope scope)
    {
        assert isPackageClass(): Debug.show(this);
        assert loader != null: Debug.show(this) + " - " + name;
        ClassSymbol clasz = new LinkedClassSymbol(this, flags, name);
        clasz.setInfo(loader);
        clasz.allConstructors().setInfo(loader);
        clasz.linkedModule().setInfo(loader);
        clasz.linkedModule().moduleClass().setInfo(loader);
        if (scope != null) scope.enterNoHide(clasz);
        if (scope != null) scope.enterNoHide(clasz.linkedModule());
        return clasz;
    }

    /**
     * Creates a new error class owned by this symbol and initializes
     * it with an error type.
     */
    public ClassSymbol newErrorClass(Name name) {
        ClassSymbol symbol = newClass(pos, SYNTHETIC, name, IS_ERROR);
        Scope scope = new ErrorScope(this);
        symbol.setInfo(Type.compoundType(Type.EMPTY_ARRAY, scope, this));
        symbol.allConstructors().setInfo(Type.ErrorType);
        return symbol;
    }

    /** Creates a new term owned by this symbol. */
    final Symbol newTerm(int pos, int flags, Name name, int attrs) {
        return new TermSymbol(this, pos, flags, name, attrs);
    }

    /** Creates a new package owned by this symbol. */
    final Symbol newPackage(int pos, Name name, Type info) {
        assert isPackageClass(): Debug.show(this);
        Symbol peckage = newModule(pos, JAVA | PACKAGE, name);
        if (info == null) info = Type.compoundType(
            Type.EMPTY_ARRAY, new Scope(), peckage.moduleClass());
        peckage.moduleClass().setInfo(info);
        return peckage;
    }

    /** Creates a new class owned by this symbol. */
    final ClassSymbol newClass(int pos, int flags, Name name, int attrs) {
        return new ClassSymbol(this, pos, flags, name, attrs);
    }

    /** Creates a new compound class owned by this symbol. */
    final ClassSymbol newCompoundClass(Type info) {
        int pos = Position.FIRSTPOS;
        Name name = Names.COMPOUND_NAME.toTypeName();
        int flags = ABSTRACT | SYNTHETIC;
        int attrs = IS_COMPOUND;
        ClassSymbol clasz = newClass(pos, flags, name, attrs);
        clasz.setInfo(info);
        clasz.primaryConstructor().setInfo(
            Type.MethodType(Symbol.EMPTY_ARRAY, clasz.typeConstructor()));
        return clasz;
    }

// Copying & cloning ------------------------------------------------------

    /** Return a fresh symbol with the same fields as this one.
     */
    public final Symbol cloneSymbol() {
        return cloneSymbol(owner);
    }

    /** Return a fresh symbol with the same fields as this one and the
     * given owner.
     */
    public final Symbol cloneSymbol(Symbol owner) {
        Symbol clone = cloneSymbolImpl(owner, attrs);
        clone.setInfo(info());
        return clone;
    }

    protected abstract Symbol cloneSymbolImpl(Symbol owner, int attrs);

    /** Returns a shallow copy of the given array. */
    public static Symbol[] cloneArray(Symbol[] array) {
        return cloneArray(0, array, 0);
    }

    /**
     * Returns a shallow copy of the given array prefixed by "prefix"
     * null items.
     */
    public static Symbol[] cloneArray(int prefix, Symbol[] array) {
        return cloneArray(prefix, array, 0);
    }

    /**
     * Returns a shallow copy of the given array suffixed by "suffix"
     * null items.
     */
    public static Symbol[] cloneArray(Symbol[] array, int suffix) {
        return cloneArray(0, array, suffix);
    }

    /**
     * Returns a shallow copy of the given array prefixed by "prefix"
     * null items and suffixed by "suffix" null items.
     */
    public static Symbol[] cloneArray(int prefix, Symbol[] array, int suffix) {
        assert prefix >= 0 && suffix >= 0: prefix + " - " + suffix;
        int size = prefix + array.length + suffix;
        if (size == 0) return EMPTY_ARRAY;
        Symbol[] clone = new Symbol[size];
        for (int i = 0; i < array.length; i++) clone[prefix + i] = array[i];
        return clone;
    }

    /** Returns the concatenation of the two arrays. */
    public static Symbol[] concat(Symbol[] array1, Symbol[] array2) {
        if (array1.length == 0) return array2;
        if (array2.length == 0) return array1;
        Symbol[] clone = cloneArray(array1.length, array2);
        for (int i = 0; i < array1.length; i++) clone[i] = array1[i];
        return clone;
    }

// Setters ---------------------------------------------------------------

    /** Set owner */
    public Symbol setOwner(Symbol owner) {
        assert !isConstructor() && !isNone() && !isError(): Debug.show(this);
        setOwner0(owner);
        return this;
    }
    protected void setOwner0(Symbol owner) {
        this.owner = owner;
    }

    /** Set type -- this is an alias for setInfo(Type info) */
    public final Symbol setType(Type info) { return setInfo(info); }

    /**
     * Set initial information valid from start of current phase. This
     * information is visible in the current phase and will be
     * transformed by the current phase (except if current phase is
     * the first one).
     */
    public Symbol setInfo(Type info) {
        return setInfoAt(info, Global.instance.currentPhase);
    }

    /**
     * Set initial information valid from start of given phase. This
     * information is visible in the given phase and will be
     * transformed by the given phase.
     */
    private final Symbol setInfoAt(Type info, Phase phase) {
        assert info != null: Debug.show(this);
        assert phase != null: Debug.show(this);
        assert !isConstructor()
            || info instanceof Type.LazyType
            || info == Type.NoType
            || info == Type.ErrorType
            || info instanceof Type.MethodType
            || info instanceof Type.OverloadedType
            || info instanceof Type.PolyType
            : "illegal type for " + this + ": " + info;
        infos = new TypeIntervalList(null, info, phase);
        if (info instanceof Type.LazyType) flags &= ~INITIALIZED;
        else flags |= INITIALIZED;
        return this;
    }

    /**
     * Set new information valid from start of next phase. This
     * information is only visible in next phase or through
     * "nextInfo". It will not be transformed by the current phase.
     */
    public final Symbol updateInfo(Type info) {
        return updateInfoAt(info, Global.instance.currentPhase.next);
    }

    /**
     * Set new information valid from start of given phase. This
     * information is only visible from the start of the given phase
     * which is also the first phase that will transform this
     * information.
     */
    private final Symbol updateInfoAt(Type info, Phase phase) {
        assert info != null: Debug.show(this);
        assert phase != null: Debug.show(this);
        assert infos != null: Debug.show(this);
        assert !phase.precedes(infos.limit()) :
            Debug.show(this) + " -- " + phase + " -- " + infos.limit();
        if (infos.limit() == phase) {
            if (infos.start == phase)
                infos = infos.prev;
            else
                infos.setLimit(infos.limit().prev);
        }
        infos = new TypeIntervalList(infos, info, phase);
        return this;
    }

    /** Set type of `this' in current class
     */
    public Symbol setTypeOfThis(Type tp) {
        throw new ApplicationError(this + ".setTypeOfThis");
    }

    /** Set the low bound of this type variable
     */
    public Symbol setLoBound(Type lobound) {
        throw new ApplicationError("setLoBound inapplicable for " + this);
    }

    /** Set the view bound of this type variable
     */
    public Symbol setVuBound(Type lobound) {
        throw new ApplicationError("setVuBound inapplicable for " + this);
    }

    /** Add an auxiliary constructor to class.
     */
    public void addConstructor(Symbol constr) {
        throw new ApplicationError("addConstructor inapplicable for " + this);
    }

// Symbol classification ----------------------------------------------------

    /** Does this symbol denote an error symbol? */
    public final boolean isError() {
        return (attrs & IS_ERROR) != 0;
    }

    /** Does this symbol denote the none symbol? */
    public final boolean isNone() {
        return kind == Kinds.NONE;
    }

    /** Does this symbol denote a type? */
    public final boolean isType() {
        return kind == TYPE || kind == CLASS || kind == ALIAS;
    }

    /** Does this symbol denote a term? */
    public final boolean isTerm() {
        return kind == VAL;
    }

    /** Does this symbol denote a value? */
    public final boolean isValue() {
        preInitialize();
        return kind == VAL && !(isModule() && isJava()) && !isPackage();
    }

    /** Does this symbol denote a stable value? */
    public final boolean isStable() {
        return kind == VAL &&
	    ((flags & DEF) == 0) &&
            ((flags & STABLE) != 0 ||
             (flags & MUTABLE) == 0 && type().isObjectType());
    }

    /** Does this symbol have the STABLE flag? */
    public final boolean hasStableFlag() {
        return (flags & STABLE) != 0;
    }

    /** Is this symbol static (i.e. with no outer instance)? */
    public final boolean isStatic() {
        return isRoot() || owner.isStaticOwner();
    }

    /** Does this symbol denote a class that defines static symbols? */
    public final boolean isStaticOwner() {
        return isPackageClass() || (isStatic() && isModuleClass()
            // !!! remove later? translation does not work (yet?)
            && isJava());
    }

    /** Is this symbol final?
     */
    public final boolean isFinal() {
	return
	    (flags & (FINAL | PRIVATE)) != 0 || isLocal() || owner.isModuleClass();
    }

    /** Does this symbol denote a variable? */
    public final boolean isVariable() {
        return kind == VAL && (flags & MUTABLE) != 0;
    }

    /** Does this symbol denote a view bounded type variable? */
    public final boolean isViewBounded() {
	Global global = Global.instance;
        return kind == TYPE && (flags & VIEWBOUND) != 0 &&
	    global.currentPhase.id <= global.PHASE.REFCHECK.id();
    }

    /**
     * Does this symbol denote a final method? A final method is one
     * that can't be overridden in a subclass. This method assumes
     * that this symbol denotes a method. It doesn't test it.
     */
    public final boolean isMethodFinal() {
        return (flags & FINAL) != 0 || isPrivate() || isLifted();
    }

    /** Does this symbol denote a sealed class symbol? */
    public final boolean isSealed() {
        return (flags & SEALED) != 0;
    }

    /** Does this symbol denote a method?
     */
    public final boolean isInitializedMethod() {
        if (infos == null) return false;
        switch (rawInfo()) {
        case MethodType(_, _):
        case PolyType(_, _):
            return true;
        case OverloadedType(Symbol[] alts, _):
            for (int i = 0; i < alts.length; i++)
                if (alts[i].isMethod()) return true;
            return false;
        default:
            return false;
        }
    }

    public final boolean isMethod() {
        initialize();
        return isInitializedMethod();
    }

    public final boolean isCaseFactory() {
        return isMethod() && !isConstructor() && (flags & CASE) != 0;
    }

    public final boolean isAbstractClass() {
        preInitialize();
        return kind == CLASS && (flags & ABSTRACT) != 0 &&
            this != Global.instance.definitions.ARRAY_CLASS;
    }

    public final boolean isAbstractOverride() {
        preInitialize();
        return (flags & (ABSTRACT | OVERRIDE)) == (ABSTRACT | OVERRIDE);
    }

    /* Does this symbol denote an anonymous class? */
    public final boolean isAnonymousClass() {
        return isClass() && (attrs & IS_ANONYMOUS) != 0;
    }

    /** Does this symbol denote the root class or root module?
     */
    public final boolean isRoot() {
        return (attrs & IS_ROOT) != 0;
    }

    /** Does this symbol denote something loaded from a Java class? */
    public final boolean isJava() {
        preInitialize();
        return (flags & JAVA) != 0;
    }

    /** Does this symbol denote a Java package? */
    public final boolean isPackage() {
        return kind == VAL && (flags & PACKAGE) != 0;
    }

    /** Does this symbol denote a Java package class? */
    public final boolean isPackageClass() {
        return kind == CLASS && (flags & PACKAGE) != 0;
    }

    /** Does this symbol denote a module? */
    public final boolean isModule() {
        return kind == VAL && (flags & MODUL) != 0;
    }

    /** Does this symbol denote a module class? */
    public final boolean isModuleClass() {
        return kind == CLASS && (flags & MODUL) != 0;
    }

    /** Does this symbol denote a class? */
    public final boolean isClass() {
        return kind == CLASS && (flags & PACKAGE) == 0;
    }

    /** Does this symbol denote a case class?
     */
    public final boolean isCaseClass() {
        preInitialize();
        return kind == CLASS && (flags & CASE) != 0;
    }

    /** Does this symbol denote a uniform (i.e. parameterless) class? */
    public final boolean isTrait() {
        //preInitialize(); todo: enable, problem is that then we cannot print
        // during unpickle
        return kind == CLASS && (flags & TRAIT) != 0;
    }

    /** Does this class symbol denote a compound type symbol? */
    public final boolean isCompoundSym() {
        return (attrs & IS_COMPOUND) != 0;
    }

    /** Does this symbol denote a this symbol? */
    public final boolean isThisSym() {
        return (attrs & IS_THISTYPE) != 0;
    }

    /** Does this symbol denote an interface? */
    public final boolean isInterface() {
        info(); // force delayed transformInfos that may change this flag
        return (flags & INTERFACE) != 0;
    }

    /** Does this symbol denote a type alias? */
    public final boolean isTypeAlias() {
        return kind == ALIAS;
    }

    /** Does this symbol denote an abstract type? */
    public final boolean isAbstractType() {
        return kind == TYPE;
    }

    /** Does this symbol denote a class type? */
    public final boolean isClassType() {
        return kind == CLASS;
    }

    /** Does this symbol denote a public symbol? */
    public final boolean isPublic() {
        return !isProtected() && !isPrivate();
    }

    /** Does this symbol denote a protected symbol? */
    public final boolean isProtected() {
        preInitialize();
        return (flags & PROTECTED) != 0;
    }

    /** Does this symbol denote a private symbol? */
    public final boolean isPrivate() {
        preInitialize();
        return (flags & PRIVATE) != 0;
    }

    /** Has this symbol been lifted? */
    public final boolean isLifted() {
        preInitialize();
        return (flags & LIFTED) != 0;
    }

    /** Does this symbol denote a deferred symbol? */
    public final boolean isDeferred() {
        return (flags & DEFERRED) != 0;
    }

    /** Does this symbol denote a synthetic symbol? */
    public final boolean isSynthetic() {
        return (flags & SYNTHETIC) != 0;
    }

    /** Does this symbol denote an accessor? */
    public final boolean isAccessor() {
        return (flags & ACCESSOR) != 0;
    }

    /** Does this symbol denote an access method? (a method to access
     * private of protected members from inner classes) */
    public final boolean isAccessMethod() {
        return (attrs & IS_ACCESSMETHOD) != 0;
    }

    /** Is this symbol locally defined? I.e. not a member of a class or module */
    public final boolean isLocal() {
        return owner.kind == VAL &&
            !((flags & PARAM) != 0 && owner.isPrimaryConstructor());
    }

    /** Is this symbol a parameter? Includes type parameters of methods.
     */
    public final boolean isParameter() {
        return (flags & PARAM) != 0;
    }

    /** Is this symbol a def parameter?
     */
    public final boolean isDefParameter() {
        return (flags & (PARAM | DEF)) == (PARAM | DEF);
    }

    /** Is this class locally defined?
     *  A class is local, if
     *   - it is anonymous, or
     *   - its owner is a value
     *   - it is defined within a local class
     */
    public final boolean isLocalClass() {
        return isClass() &&
            (isAnonymousClass() ||
             owner.isValue() ||
             owner.isLocalClass());
    }

    /** Is this symbol an instance initializer? */
    public boolean isInitializer() {
        return false;
    }

    /** Is this symbol a constructor? */
    public final boolean isConstructor() {
        return (attrs & IS_CONSTRUCTOR) != 0;
    }

    /** Is this symbol the primary constructor of a type? */
    public final boolean isPrimaryConstructor() {
        return isConstructor() && this == constructorClass().primaryConstructor();
    }

    /** Symbol was preloaded from package
     */
    public final boolean isExternal() {
        return pos == Position.NOPOS;
    }

    /** Is this symbol an overloaded symbol? */
    public final boolean isOverloaded() {
        switch (info()) {
        case OverloadedType(_,_): return true;
        default                 : return false;
        }
    }

    /** Does this symbol denote a label? */
    public final boolean isLabel() {
        return (attrs & IS_LABEL) != 0;
    }

    /** Is this symbol accessed? */
    public final boolean isAccessed() {
        return (flags & ACCESSED) != 0;
    }

    /** The variance of this symbol as an integer
     */
    public int variance() {
        if ((flags & COVARIANT) != 0) return 1;
        else if ((flags & CONTRAVARIANT) != 0) return -1;
        else return 0;
    }

// Symbol names ----------------------------------------------------------------

    /** Get the fully qualified name of this Symbol
     *  (this is always a normal name, never a type name)
     */

    /** Get the simple name of this Symbol (this is always a term name)
     */
    public Name simpleName() {
        if (isConstructor()) return constructorClass().name.toTermName();
        return name;
    }

// Acess to related symbols -----------------------------------------------------

    /** Get type parameters */
    public Symbol[] typeParams() {
        return EMPTY_ARRAY;
    }

    /** Get value parameters */
    public Symbol[] valueParams() {
        return EMPTY_ARRAY;
    }

    /** Get result type */
    public final Type resultType() {
        return type().resultType();
    }

    /** Get type parameters at start of next phase */
    public final Symbol[] nextTypeParams() {
        Global.instance.nextPhase();
        Symbol[] tparams = typeParams();
        Global.instance.prevPhase();
        return tparams;
    }

    /** Get value parameters at start of next phase */
    public final Symbol[] nextValueParams() {
        Global.instance.nextPhase();
        Symbol[] vparams = valueParams();
        Global.instance.prevPhase();
        return vparams;
    }

    /** Get result type at start of next phase */
    public final Type nextResultType() {
        return nextType().resultType();
    }

    /** Get all constructors of class */
    public Symbol allConstructors() {
        return NONE;
    }

    /** Get primary constructor of class */
    public Symbol primaryConstructor() {
        return NONE;
    }

    /**
     * Returns the class linked to this module or null if there is no
     * such class. The returned value remains the same for the whole
     * life of the symbol.
     *
     * See method "linkedModule" to learn more about linked modules
     * and classes.
     */
    public ClassSymbol linkedClass() {
        assert isModule(): "not a module: " + Debug.show(this);
        return null;
    }

    /**
     * Returns the module linked to this class or null if there is no
     * such module. The returned value remains the same for the whole
     * life of the symbol.
     *
     * Linked modules and classes are intended to be used by the
     * symbol table loader. They are needed because it is impossible
     * to know from the name of a class or source file if it defines a
     * class or a module. For that reason a class and a module (each
     * linked to the other) are created for each of those files. Once
     * the file is read the class, the module or both are initialized
     * depending on what the file defines.
     *
     * It is guaranteed that if a class "c" has a linked module then
     * "c.linkedModule().linkedClasss() == c" and that if a module "m"
     * has a linked class then "m.linkedClasss().linkedModule() == m".
     *
     * The linked module of a Java class, is the module that contains
     * the static members of that class. A Java class has always a
     * linked module.
     *
     * The linked module of a Scala class, is the module with the same
     * name declared in the same scope. A Scala class may or may not
     * have a linked module. However, this does not depend on the
     * presence or absence of a module with the same name but on how
     * the class is created. Therefore a Scala class may have no
     * linked module even though there exists a module with the same
     * name in the same scope. A Scala class may also have a linked
     * module even though there exists no module with the same name in
     * the same scope. In the latter case, the linked would be
     * initialized to NoType (which prevents accesses to it).
     *
     * There is a last catch about linked modules. It may happen that
     * the symbol returned by "linkedModule" is not a module (and that
     * method "linkedClass" works on a non-module symbol). At creation
     * time, linked modules are always modules, but at initialization
     * time, it may be discovered that the module is in fact a case
     * class factory method. In that case, the module is downgraded to
     * a non-module term. This implies that from then on calls to its
     * method "moduleClass" will fail, but the links defined by the
     * methods "linkedModule" and "linkedClass" remain unchanged.
     */
    public ModuleSymbol linkedModule() {
        assert isClassType(): "not a class: " + Debug.show(this);
        return null;
    }

    /** Get owner */
    public Symbol owner() {
        return owner;
    }

    /** Get owner, but if owner is primary constructor of a class,
     *  get class symbol instead. This is useful for type parameters
     *  and value parameters in classes which have the primary constructor
     *  as owner.
     */
    public Symbol classOwner() {
        Symbol owner = owner();
        Symbol clazz = owner.constructorClass();
        if (clazz.primaryConstructor() == owner) return clazz;
        else return owner;
    }

    /** The next enclosing class */
    public Symbol enclClass() {
        return owner().enclClass();
    }

    /** The next enclosing method */
    public Symbol enclMethod() {
        return isMethod() ? this : owner().enclMethod();
    }

    /** If this is a constructor, return the class it constructs.
     *  Otherwise return the symbol itself.
     */
    public Symbol constructorClass() {
        return this;
    }

    /** Return first alternative if this has a (possibly lazy)
     *  overloaded type, otherwise symbol itself.
     *  Needed in ClassSymbol.primaryConstructor() and in UnPickle.
     */
    public Symbol firstAlternative() {
        if (infos == null)
            return this;
        else if (infos.info instanceof Type.OverloadedType)
            return infos.info.alternativeSymbols()[0];
        else if (infos.info instanceof LazyOverloadedType)
            return ((LazyOverloadedType) infos.info).sym1.firstAlternative();
        else
            return this;
    }

    /**
     * Returns the class of this module. This method may be invoked
     * only on module symbols. It returns always a non-null module
     * class symbol whose identity never changes.
     */
    public ModuleClassSymbol moduleClass() {
        throw Debug.abort("not a module", this);
    }

    /**
     * Returns the source module of this module class. This method may
     * be invoked only on module class symbols. It returns always a
     * non-null module symbol whose identity never changes.
     *
     * This method should be used with great care. If possible, one
     * should always use moduleClass instead. For example, one should
     * write "m.moduleClass()==c" rather than "m==c.sourceModule()".
     *
     * This method is problematic because the module - module-class
     * relation is not a one - one relation. There might be more than
     * one module that share the same module class. In that case, the
     * source module of the module class is the module that created
     * the class. This implies that "m.moduleClass().sourceModule()"
     * may be different of "m". However, its is guaranteed that
     * "c.sourceModule().moduleClass()" always returns "c".
     *
     * Phases like "AddInterfaces" and "ExpandMixins" are two examples
     * of phases that create additional modules referring the same
     * module class.
     *
     * Even if a module class is related to only one module, the use
     * of this method may still be dangerous. The problem is that
     * modules and module classes are not always as related as one
     * might expect. For example, modules declared in a function are
     * lifted out of the function by phase "LambdaLift". During this
     * process, the module value is transformed into a module method
     * with a "Ref" argument. If the "sourceModule" method is used to
     * replace references to module classes by references to their
     * source modules and this is done it naively with the class of a
     * lifted module, it will yield wrong code because the the "Ref"
     * argument will be missing.
     */
    public ModuleSymbol sourceModule() {
        throw Debug.abort("not a module class", this);
    }

    /** if type is a (possibly lazy) overloaded type, return its alternatves
     *  else return array consisting of symbol itself
     */
    public Symbol[] alternativeSymbols() {
        Symbol[] alts = type().alternativeSymbols();
        if (alts.length == 0) return new Symbol[]{this};
        else return alts;
    }

    /** if type is a (possibly lazy) overloaded type, return its alternatves
     *  else return array consisting of type itself
     */
    public Type[] alternativeTypes() {
        return type().alternativeTypes();
    }

    /** The symbol accessed by this accessor function.
     */
    public Symbol accessed() {
        assert (flags & ACCESSOR) != 0;
        String name1 = name.toString();
        if (name1.endsWith(Names._EQ.toString()))
            name1 = name1.substring(0, name1.length() - Names._EQ.length());
        return owner.lookup(Name.fromString(name1 + "$"));
    }

    /** The members of this class or module symbol
     */
    public Scope members() {
        return info().members();
    }

    /** Lookup symbol with given name; return Symbol.NONE if not found.
     */
    public Symbol lookup(Name name) {
        return info().lookup(name);
    }

// Symbol types --------------------------------------------------------------

    /** Was symbol's type updated during given phase? */
    public final boolean isUpdatedAt(Phase phase) {
        Phase next = phase.next;
        TypeIntervalList infos = this.infos;
        while (infos != null) {
            if (infos.start == next) return true;
            if (infos.limit().precedes(next)) return false;
            infos = infos.prev;
        }
        return false;
    }

    /** Is this symbol locked? */
    public final boolean isLocked() {
        return (flags & LOCKED) != 0;
    }

    /** Is this symbol initialized? */
    public final boolean isInitialized() {
        return (flags & INITIALIZED) != 0;
    }

    /** Initialize the symbol */
    public final Symbol initialize() {
        info();
        return this;
    }

    /** Make sure symbol is entered
     */
    public final void preInitialize() {
        //todo: clean up
        if (infos.info instanceof SymbolLoader)
            infos.info.complete(this);
    }

    /** Get info at start of current phase; This is:
     *  for a term symbol, its type
     *  for a type variable, its bound
     *  for a type alias, its right-hand side
     *  for a class symbol, the compound type consisting of
     *  its baseclasses and members.
     */
    public final Type info() {
        //if (isModule()) moduleClass().initialize();
        if ((flags & INITIALIZED) == 0) {
            Global global = Global.instance;
            Phase current = global.currentPhase;
            global.currentPhase = rawFirstInfoStartPhase();
            Type info = rawFirstInfo();
            assert info != null : this;
            if ((flags & LOCKED) != 0) {
                setInfo(Type.ErrorType);
                flags |= INITIALIZED;
                throw new CyclicReference(this, info);
            }
            flags |= LOCKED;
            //System.out.println("completing " + this);//DEBUG
            info.complete(this);
            flags = flags & ~LOCKED;
            if (info instanceof SourceCompleter && (flags & SNDTIME) == 0) {
                flags |= SNDTIME;
                Type tp = info();
                flags &= ~SNDTIME;
            } else {
                assert !(rawInfo() instanceof Type.LazyType) : this;
                //flags |= INITIALIZED;
            }
            //System.out.println("done: " + this);//DEBUG
            global.currentPhase = current;
        }
        return rawInfo();
    }

    /** Get info at start of next phase
     */
    public final Type nextInfo() {
        Global.instance.nextPhase();
        Type info = info();
        Global.instance.prevPhase();
        return info;
    }

    /** Get info at start of given phase
     */
    protected final Type infoAt(Phase phase) {
        Global global = phase.global;
        Phase current = global.currentPhase;
        global.currentPhase = phase;
        Type info = info();
        global.currentPhase = current;
        return info;
    }

    /** Get info at start of current phase, without forcing lazy types.
     */
    public final Type rawInfo() {
        return rawInfoAt(Global.instance.currentPhase);
    }

    /** Get info at start of next phase, without forcing lazy types.
     */
    public final Type rawNextInfo() {
        Global.instance.nextPhase();
        Type info = rawInfo();
        Global.instance.prevPhase();
        return info;
    }

    /** Get info at start of given phase, without forcing lazy types.
     */
    private final Type rawInfoAt(Phase phase) {
        //if (infos == null) return Type.NoType;//DEBUG
        assert infos != null : this;
        assert phase != null : this;
        if (infos.limit().id <= phase.id) {
            switch (infos.info) {
            case LazyType():
                // don't force lazy types
                return infos.info;
            }
            while (infos.limit() != phase) {
                Phase limit = infos.limit();
                Type info = transformInfo(limit, infos.info);
                assert info != null: Debug.show(this) + " -- " + limit;
                if (info != infos.info) {
                    infos = new TypeIntervalList(infos, info, limit.next);
                } else {
                    infos.setLimit(limit.next);
                }
            }
            return infos.info;
        } else {
            TypeIntervalList infos = this.infos;
            while (phase.id < infos.start.id && infos.prev != null)
                infos = infos.prev;
            return infos.info;
        }
    }
    // where
        private Type transformInfo(Phase phase, Type info) {
            Global global = phase.global;
            Phase current = global.currentPhase;
            switch (info) {
            case ErrorType:
            case NoType:
                return info;
            case OverloadedType(Symbol[] alts, Type[] alttypes):
                global.currentPhase = phase.next;
                for (int i = 0; i < alts.length; i++) {
                    Type type = alts[i].info();
                    if (type != alttypes[i]) {
                        Type[] types = new Type[alttypes.length];
                        for (int j = 0; j < i; j++) types[j] = alttypes[j];
                        alttypes[i] = type;
                        for (; i < alts.length; i++)
                            types[i] = alts[i].info();
                        global.currentPhase = current;
                        return Type.OverloadedType(alts, types);
                    }
                }
                global.currentPhase = current;
                return info;
            default:
                global.currentPhase = phase;
                info = phase.transformInfo(this, info);
                global.currentPhase = current;
                return info;
            }
        }

    /** Get first defined info, without forcing lazy types.
     */
    public final Type rawFirstInfo() {
        TypeIntervalList infos = this.infos;
        assert infos != null : this;
        while (infos.prev != null) infos = infos.prev;
        return infos.info;
    }

    /** Get phase that first defined an info, without forcing lazy types.
     */
    public final Phase rawFirstInfoStartPhase() {
        TypeIntervalList infos = this.infos;
        assert infos != null : this;
        while (infos.prev != null) infos = infos.prev;
        return infos.start;
    }

    /** Get type at start of current phase. The type of a symbol is:
     *  for a type symbol, the type corresponding to the symbol itself
     *  for a term symbol, its usual type
     */
    public Type type() {
        return info();
    }
    public Type getType() {
        return info();
    }

    /** Get type at start of next phase
     */
    public final Type nextType() {
        Global.instance.nextPhase();
        Type type = type();
        Global.instance.prevPhase();
        return type;
    }

    /** The infos of these symbols as an array.
     */
    static public Type[] info(Symbol[] syms) {
        Type[] tps = new Type[syms.length];
        for (int i = 0; i < syms.length; i++)
            tps[i] = syms[i].info();
        return tps;
    }

    /** The types of these symbols as an array.
     */
    static public Type[] type(Symbol[] syms) {
        Type[] tps = new Type[syms.length];
        for (int i = 0; i < syms.length; i++)
            tps[i] = syms[i].type();
        return tps;
    }
    static public Type[] getType(Symbol[] syms) {
	return type(syms);
    }

    /** Get static type. */
    public final Type staticType() {
        return staticType(Type.EMPTY_ARRAY);
    }
    /** Get static type with given type argument. */
    public final Type staticType(Type arg0) {
        return staticType(new Type[]{arg0});
    }
    /** Get static type with given type arguments. */
    public final Type staticType(Type arg0, Type arg1) {
        return staticType(new Type[]{arg0, arg1});
    }
    /** Get static type with given type arguments. */
    public final Type staticType(Type[] args) {
        Type prefix = owner.staticPrefix();
        if (isType()) return Type.typeRef(prefix, this, args);
        assert args.length == 0: Debug.show(this, args);
        return prefix.memberType(this);
    }

    /** Get static prefix. */
    public final Type staticPrefix() {
        assert isStaticOwner(): Debug.show(this) + " - " + isTerm() + " - " + isModuleClass() + " - " + owner().isStaticOwner() + " - " + isJava();
        Global global = Global.instance;
        if (global.PHASE.EXPLICITOUTER.id() < global.currentPhase.id)
            return Type.NoPrefix;
        if (isRoot()) return thisType();
        assert sourceModule().owner() == owner(): Debug.show(this);
        assert sourceModule().type().isObjectType(): Debug.show(this);
        return Type.singleType(owner.staticPrefix(), sourceModule());
    }

    /** The type constructor of a symbol is:
     *  For a type symbol, the type corresponding to the symbol itself, excluding
     *  parameters.
     *  Not applicable for term symbols.
     */
    public Type typeConstructor() {
        throw new ApplicationError("typeConstructor inapplicable for " + this);
    }

    /** The low bound of this type variable
     */
    public Type loBound() {
        return Global.instance.definitions.ALL_TYPE();
    }

    /** The view bound of this type variable
     */
    public Type vuBound() {
        return Global.instance.definitions.ANY_TYPE();
    }

    /** Get this.type corresponding to this symbol
     */
    public Type thisType() {
        return Type.NoPrefix;
    }

    /** Get type of `this' in current class.
     */
    public Type typeOfThis() {
        return type();
    }

    /** Get this symbol of current class
     */
    public Symbol thisSym() { return this; }


    /** A total ordering between symbols that refines the class
     *  inheritance graph (i.e. subclass.isLess(superclass) always holds).
     */
    public boolean isLess(Symbol that) {
        if (this == that) return false;
        int diff;
        if (this.isType()) {
            if (that.isType()) {
                diff = this.closure().length - that.closure().length;
                if (diff > 0) return true;
                if (diff < 0) return false;
            } else {
                return true;
            }
        } else if (that.isType()) {
            return false;
        }
        return this.id < that.id;
    }

    /** Return the symbol's type itself followed by all its direct and indirect
     *  base types, sorted by isLess(). Overridden for class symbols.
     */
    public Type[] closure() {
        return info().closure();
    }

    /** Return position of `c' in the closure of this type; -1 if not there.
     */
    public int closurePos(Symbol c) {
        if (this == c) return 0;
        if (c.isCompoundSym()) return -1;
        Type[] closure = closure();
        int lo = 0;
        int hi = closure.length - 1;
        while (lo <= hi) {
            int mid = (lo + hi) / 2;
            Symbol clsym = closure[mid].symbol();
            if (c == clsym) return mid;
            else if (c.isLess(clsym)) hi = mid - 1;
            else if (clsym.isLess(c)) lo = mid + 1;
            else throw new ApplicationError();
        }
        return -1;
    }

    public Type baseType(Symbol sym) {
        int i = closurePos(sym);
        if (i >= 0) return closure()[i];
        else return Type.NoType;
    }

    /** Is this class a subclass of `c'? I.e. does it have a type instance
     *  of `c' as indirect base class?
     */
    public boolean isSubClass(Symbol c) {
        return this == c ||
            c.isError() ||
            closurePos(c) >= 0 ||
            this == Global.instance.definitions.ALL_CLASS ||
            (this == Global.instance.definitions.ALLREF_CLASS &&
             c != Global.instance.definitions.ALL_CLASS &&
             c.isSubClass(Global.instance.definitions.ANYREF_CLASS));
    }

    /** Get base types of this symbol */
    public Type[] parents() {
        return info().parents();
    }

// ToString -------------------------------------------------------------------

    /** String representation of symbol's simple name.
     *  Translates expansions of operators back to operator symbol. E.g.
     *  $eq => =.
     */
    public String nameString() {
        return NameTransformer.decode(simpleName());
    }

    /** String representation, including symbol's kind
     *  e.g., "class Foo", "function Bar".
     */
    public String toString() {
        return new SymbolTablePrinter().printSymbolKindAndName(this).toString();
    }

    /** String representation of location.
     */
    public String locationString() {
        if (owner.kind == CLASS &&
            !owner.isAnonymousClass() && !owner.isCompoundSym() ||
            Global.instance.debug)
            return " in " +
                (owner.isModuleClass() ? owner.sourceModule() : owner);
        else
            return "";
    }

    /** String representation of definition.
     */
    public String defString() {
        return new SymbolTablePrinter().printSignature(this).toString();
    }

    public static String[] defString(Symbol[] defs) {
        String[] strs = new String[defs.length];
        for (int i = 0; i < defs.length; i++)
            strs[i] = defs[i].defString();
        return strs;
    }

// Overloading and Overriding -------------------------------------------

    /** Add another overloaded alternative to this symbol.
     */
    public Symbol overloadWith(Symbol that) {
        assert isTerm() : Debug.show(this);
        assert this.name == that.name : Debug.show(this) + " <> " + Debug.show(that);
        //assert this.owner == that.owner : Debug.show(this) + " != " + Debug.show(that);
        assert this.isConstructor() == that.isConstructor();
        int overflags;
	//if (this.owner == that.owner)
	    overflags = (this.flags & that.flags &
			 (JAVA | ACCESSFLAGS | DEFERRED | PARAM | SYNTHETIC)) |
		((this.flags | that.flags) & ACCESSOR);
	// else // it's an inherited overloaded alternative
	//    overflags = this.flags & SOURCEFLAGS;
        Symbol overloaded = (this.isConstructor())
            ? this.constructorClass().newConstructor(this.constructorClass().pos, overflags)
            : owner.newTerm(pos, overflags, name, 0);
        overloaded.setInfo(new LazyOverloadedType(this, that));
        return overloaded;
    }

    /** A lazy type which, when forced computed the overloaded type
     *  of symbols `sym1' and `sym2'. It also checks that this type is well-formed.
     */
    public static class LazyOverloadedType extends Type.LazyType {
        Symbol sym1;
        Symbol sym2;
        LazyOverloadedType(Symbol sym1, Symbol sym2) {
            this.sym1 = sym1;
            this.sym2 = sym2;
        }

        public Symbol[] alternativeSymbols() {
            Symbol[] alts1 = sym1.alternativeSymbols();
            Symbol[] alts2 = sym2.alternativeSymbols();
            Symbol[] alts3 = new Symbol[alts1.length + alts2.length];
            System.arraycopy(alts1, 0, alts3, 0, alts1.length);
            System.arraycopy(alts2, 0, alts3, alts1.length, alts2.length);
            return alts3;
        }

        public Type[] alternativeTypes() {
            Type[] alts1 = sym1.alternativeTypes();
            Type[] alts2 = sym2.alternativeTypes();
            Type[] alts3 = new Type[alts1.length + alts2.length];
            System.arraycopy(alts1, 0, alts3, 0, alts1.length);
            System.arraycopy(alts2, 0, alts3, alts1.length, alts2.length);
            return alts3;
        }

        public void complete(Symbol overloaded) {
            overloaded.setInfo(
                Type.OverloadedType(
                    alternativeSymbols(), alternativeTypes()));
        }

        public String toString() {
            return "LazyOverloadedType(" + sym1 + "," + sym2 + ")";
        }
    }

    /**
     * Returns the symbol in type "base" which is overridden by this
     * symbol in class "this.owner()". Returns "NONE" if no such
     * symbol exists. The type "base" must be a supertype of class
     * "this.owner()". If "exact" is true, overriding is restricted to
     * symbols that have the same type. The method may return this
     * symbol only if "base.symbol()" is equal to "this.owner()".
     */
    public final Symbol overriddenSymbol(Type base, boolean exact) {
        return overriddenSymbol(base, owner(), exact);
    }
    public final Symbol overriddenSymbol(Type base) {
        return overriddenSymbol(base, false);
    }

    /**
     * Returns the symbol in type "base" which is overridden by this
     * symbol in "clasz". Returns "NONE" if no such symbol exists. The
     * type "base" must be a supertype of "clasz" and "this.owner()"
     * must be a superclass of "clasz". If "exact" is true, overriding
     * is restricted to symbols that have the same type.  The method
     * may return this symbol if "base.symbol()" is a subclass of
     * "this.owner()".
     */
    public final Symbol overriddenSymbol(Type base, Symbol clasz, boolean exact) {
        Type.Relation relation = exact
            ? Type.Relation.SameType
            : Type.Relation.SuperType;
        return base.lookup(this, clasz.thisType(), relation);
    }
    public final Symbol overriddenSymbol(Type base, Symbol clasz) {
        return overriddenSymbol(base, clasz, false);
    }

    /**
     * Returns the symbol in type "sub" which overrides this symbol in
     * class "sub.symbol()". Returns this symbol if no such symbol
     * exists. The class "sub.symbol()" must be a subclass of
     * "this.owner()". If "exact" is true, overriding is restricted to
     * symbols that have the same type.
     */
    public final Symbol overridingSymbol(Type sub, boolean exact) {
        Type.Relation relation = exact
            ? Type.Relation.SameType
            : Type.Relation.SubType;
        return sub.lookup(this, sub, relation);
    }
    public final Symbol overridingSymbol(Type sub) {
        return overridingSymbol(sub, false);
    }

    /** Does this symbol override that symbol?
     */
    public boolean overrides(Symbol that) {
        return
            ((this.flags | that.flags) & PRIVATE) == 0 &&
            this.name == that.name &&
            owner.thisType().memberType(this).derefDef().isSubType(
                owner.thisType().memberType(that).derefDef());
    }

    /** Reset symbol to initial state
     */
    public void reset(Type completer) {
        this.flags &= SOURCEFLAGS;
        this.pos = 0;
        this.infos = null;
        this.setInfo(completer);
    }

    /**
     * Returns the symbol to use in case of a rebinding due to a more
     * precise type prefix.
     */
    public Symbol rebindSym() {
        return this;
    }

    /** return a tag which (in the ideal case) uniquely identifies
     *  class symbols
     */
    public int tag() {
        return name.toString().hashCode();
    }

    public void addInheritedOverloaded(Type owntype) {
	if (false && owner().kind == CLASS && !isConstructor() && owner().lookup(name) == this) {
	    // it's a class member which is not an overloaded alternative
	    Symbol sym = Type.lookupNonPrivate(owner().parents(), name);
	    if (sym.kind == VAL) {
		Type symtype = owner.thisType().memberType(sym);
		switch (symtype) {
		case OverloadedType(Symbol[] alts, Type[] alttypes):
		    for (int i = 0; i < alts.length; i++)
			addInheritedOverloaded(owntype, alts[i], alttypes[i]);
		    break;
		default:
		    addInheritedOverloaded(owntype, sym, symtype);
		}
	    }
	}
    }

    private void addInheritedOverloaded(Type owntype, Symbol sym, Type symtype) {
	if (!owntype.overrides(symtype)) {
	    System.out.println(owner() + " inherits overloaded: " + sym + ":" + symtype + sym.locationString());//debug
	    owner().members().lookupEntry(name).setSymbol(overloadWith(sym));
	    //System.out.println("type is now: " + owner().members().lookup(name).type());
	}
    }

    public Type removeInheritedOverloaded(Type owntype) {
	//assert name != Names.toString ||
	//    Global.instance.currentPhase.id != Global.instance.PHASE.UNCURRY.id();
	switch (owntype) {
	case OverloadedType(Symbol[] alts, Type[] alttypes):
	    int n = 0;
	    for (int i = 0; i < alts.length; i++)
		if (alts[i].owner() == owner()) n++;
	    if (n < alts.length) {
		Symbol[] alts1 = new Symbol[n];
		Type[] alttypes1 = new Type[n];
		int j = 0;
		for (int i = 0; i < alts.length; i++) {
		    if (alts[i].owner() == owner()) {
			alts1[j] = alts[i];
			alttypes1[j] = alttypes[i];
			j++;
		    } else {
			System.out.println("removing inherited alternatve " + alts[i] + ":" + alttypes[i]);//debug
		    }
		}
		return Type.OverloadedType(alts1, alttypes1);
	    } else {
		return owntype;
	    }
	default:
	    return owntype;
	}
    }
}

/** A class for term symbols
 */
class TermSymbol extends Symbol {

    /** Constructor */
    TermSymbol(Symbol owner, int pos, int flags, Name name, int attrs) {
        super(VAL, owner, pos, flags, name, attrs);
        assert name.isTermName(): Debug.show(this);
    }

    public boolean isInitializer() {
        return name == Names.INITIALIZER;
    }

    public Symbol[] typeParams() {
        return type().typeParams();
    }

    public Symbol[] valueParams() {
        return type().valueParams();
    }

    protected Symbol cloneSymbolImpl(Symbol owner, int attrs) {
        return new TermSymbol(owner, pos, flags, name, attrs);
    }

}

/** A class for constructor symbols */
final class ConstructorSymbol extends TermSymbol {

    /** The constructed class */
    private final Symbol clasz;

    /** Initializes this instance. */
    ConstructorSymbol(Symbol clasz, int pos, int flags) {
        super(clasz.owner(), pos, flags, Names.CONSTRUCTOR, IS_CONSTRUCTOR);
        this.clasz = clasz;
    }

    public boolean isInitializer() {
        return false;
    }

    public Symbol constructorClass() {
        return clasz;
    }

    protected final Symbol cloneSymbolImpl(Symbol owner, int attrs) {
        throw Debug.abort("illegal clone of constructor", this);
    }

}

/** A class for module symbols */
public class ModuleSymbol extends TermSymbol {

    /** The module class */
    private final ModuleClassSymbol clasz;

    /** Initializes this instance. */
    private ModuleSymbol(Symbol owner, int pos, int flags, Name name,
        int attrs, ModuleClassSymbol clasz)
    {
        super(owner, pos, flags | MODUL | FINAL | STABLE, name, attrs);
        this.clasz = clasz != null ? clasz : new ModuleClassSymbol(this);
        setType(Type.typeRef(owner().thisType(), this.clasz,Type.EMPTY_ARRAY));
    }

    /** Initializes this instance. */
    ModuleSymbol(Symbol owner, int pos, int flags, Name name) {
        this(owner, pos, flags, name, 0, null);
    }

    public ModuleClassSymbol moduleClass() {
        // test may fail because loaded modules may be downgraded to
        // case class factory methods (see Symbol#linkedModule())

        assert isModule(): Debug.show(this);
        return clasz;
    }

    protected final Symbol cloneSymbolImpl(Symbol owner, int attrs) {
        return new ModuleSymbol(owner, pos, flags, name, attrs, clasz);
    }

}

/**
 * A class for linked module symbols
 *
 * @see Symbol#linkedModule()
 */
final class LinkedModuleSymbol extends ModuleSymbol {

    /** The linked class */
    private final LinkedClassSymbol clasz;

    /** Initializes this instance. */
    LinkedModuleSymbol(LinkedClassSymbol clasz) {
        super(clasz.owner(), clasz.pos, clasz.flags & JAVA,
            clasz.name.toTermName());
        this.clasz = clasz;
    }

    public ClassSymbol linkedClass() {
        return clasz;
    }

}

/** A base class for all type symbols.
 *  It has AliasTypeSymbol, AbsTypeSymbol, ClassSymbol as subclasses.
 */
abstract class TypeSymbol extends Symbol {

     /** The history of closures of this symbol */
    private final History/*<Type[]>*/ closures;

    /** A cache for type constructors
     */
    private Type tycon = null;

    /** The primary constructor of this type */
    private Symbol constructor;

    /** Constructor */
    public TypeSymbol(int kind, Symbol owner, int pos, int flags, Name name, int attrs) {
        super(kind, owner, pos, flags, name, attrs);
        this.closures = new ClosureHistory();
        assert name.isTypeName() : this;
        this.constructor = newConstructor(pos, flags & CONSTRFLAGS);
    }

    protected final void copyConstructorInfo(TypeSymbol other) {
        {
            Type info = primaryConstructor().info().cloneType(
                primaryConstructor(), other.primaryConstructor());
            if (!isTypeAlias()) info = fixConstrType(info, other);
            other.primaryConstructor().setInfo(info);
        }
        Symbol[] alts = allConstructors().alternativeSymbols();
        for (int i = 1; i < alts.length; i++) {
            Symbol constr = other.newConstructor(alts[i].pos, alts[i].flags);
            other.addConstructor(constr);
            Type info = alts[i].info().cloneType(alts[i], constr);
            if (!isTypeAlias()) info = fixConstrType(info, other);
            constr.setInfo(info);
        }
    }

    private final Type fixConstrType(Type type, Symbol clone) {
        switch (type) {
        case MethodType(Symbol[] vparams, Type result):
            result = fixConstrType(result, clone);
            return new Type.MethodType(vparams, result);
        case PolyType(Symbol[] tparams, Type result):
            result = fixConstrType(result, clone);
            return new Type.PolyType(tparams, result);
        case TypeRef(Type pre, Symbol sym, Type[] args):
            if (sym != this && isTypeAlias() && owner().isCompoundSym())
                return type;
            assert sym == this: Debug.show(sym) + " != " + Debug.show(this);
            return Type.typeRef(pre, clone, args);
        case LazyType():
            return type;
        default:
            throw Debug.abort("unexpected constructor type:" + clone + ":" + type);
        }
    }

    /** add a constructor
     */
    public final void addConstructor(Symbol constr) {
        assert constr.isConstructor(): Debug.show(constr);
        constructor = constructor.overloadWith(constr);
    }

    /** Get primary constructor */
    public final Symbol primaryConstructor() {
        return constructor.firstAlternative();
    }

    /** Get all constructors */
    public final Symbol allConstructors() {
        return constructor;
    }

    /** Get type parameters */
    public final Symbol[] typeParams() {
        return primaryConstructor().info().typeParams();
    }

    /** Get value parameters */
    public final Symbol[] valueParams() {
        return (kind == CLASS) ? primaryConstructor().info().valueParams()
            : Symbol.EMPTY_ARRAY;
    }

    /** Get type constructor */
    public final Type typeConstructor() {
        if (tycon == null)
            tycon = Type.typeRef(owner().thisType(), this, Type.EMPTY_ARRAY);
        return tycon;
    }

    public Symbol setOwner(Symbol owner) {
        tycon = null;
        constructor.setOwner0(owner);
        switch (constructor.type()) {
        case OverloadedType(Symbol[] alts, _):
            for (int i = 0; i < alts.length; i++) alts[i].setOwner0(owner);
        }
        return super.setOwner(owner);
    }

    /** Get type */
    public final Type type() {
        return primaryConstructor().type().resultType();
    }
    public final Type getType() {
        return primaryConstructor().type().resultType();
    }

    /**
     * Get closure at start of current phase. The closure of a symbol
     * is a list of types which contains the type of the symbol
     * followed by all its direct and indirect base types, sorted by
     * isLess().
     */
    public final Type[] closure() {
        if (kind == ALIAS) return info().symbol().closure();
        return (Type[])closures.getValue(this);
    }

    public void reset(Type completer) {
        super.reset(completer);
        closures.reset();
        tycon = null;
    }


    protected final Symbol cloneSymbolImpl(Symbol owner, int attrs) {
        TypeSymbol clone = cloneTypeSymbolImpl(owner, attrs);
        copyConstructorInfo(clone);
        return clone;
    }

    protected abstract TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs);
}

final class AliasTypeSymbol extends TypeSymbol {

    /** Initializes this instance. */
    AliasTypeSymbol(Symbol owner, int pos, int flags, Name name, int attrs) {
        super(ALIAS, owner, pos, flags, name, attrs);
    }

    protected TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
        return new AliasTypeSymbol(owner, pos, flags, name, attrs);
    }

}

final class AbsTypeSymbol extends TypeSymbol {

    private Type lobound = null;
    private Type vubound = null;

    /** Initializes this instance. */
    AbsTypeSymbol(Symbol owner, int pos, int flags, Name name, int attrs) {
        super(TYPE, owner, pos, flags, name, attrs);
        allConstructors().setInfo(Type.MethodType(EMPTY_ARRAY, Type.typeRef(owner.thisType(), this, Type.EMPTY_ARRAY)));
    }

    public Type loBound() {
        initialize();
        return lobound == null ? Global.instance.definitions.ALL_TYPE() : lobound;
    }

    public Type vuBound() {
        initialize();
        return !isViewBounded() || vubound == null
	    ? Global.instance.definitions.ANY_TYPE() : vubound;
    }

    public Symbol setLoBound(Type lobound) {
        this.lobound = lobound;
        return this;
    }

    public Symbol setVuBound(Type vubound) {
	this.vubound = vubound;
        return this;
    }

    protected TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
        TypeSymbol clone = new AbsTypeSymbol(owner, pos, flags, name, attrs);
        clone.setLoBound(loBound());
        clone.setVuBound(vuBound());
        return clone;
    }

}

/** A class for class symbols. */
public class ClassSymbol extends TypeSymbol {

    /** The given type of self, or NoType, if no explicit type was given.
     */
    private Symbol thisSym = this;

    public Symbol thisSym() { return thisSym; }

    /** A cache for this.thisType()
     */
    final private Type thistp = Type.ThisType(this);

    private final Symbol rebindSym;

    /** Initializes this instance. */
    ClassSymbol(Symbol owner, int pos, int flags, Name name, int attrs) {
        super(CLASS, owner, pos, flags, name, attrs);
        this.rebindSym = owner.newTypeAlias(pos, 0, Names.ALIAS(this));
        Type rebindType = new ClassAliasLazyType();
        this.rebindSym.setInfo(rebindType);
        this.rebindSym.primaryConstructor().setInfo(rebindType);
    }

    private class ClassAliasLazyType extends Type.LazyType {
        public void complete(Symbol ignored) {
            Symbol clasz = ClassSymbol.this;
            Symbol alias = rebindSym;
            Type prefix = clasz.owner().thisType();
            Type constrtype = clasz.type();
            constrtype = Type.MethodType(Symbol.EMPTY_ARRAY, constrtype);
            constrtype = Type.PolyType(clasz.typeParams(), constrtype);
            constrtype = constrtype.cloneType(
                clasz.primaryConstructor(), alias.primaryConstructor());
            alias.primaryConstructor().setInfo(constrtype);
            alias.setInfo(constrtype.resultType());
        }
    }

    /** Creates the root class. */
    public static Symbol newRootClass(Global global) {
        int pos = Position.NOPOS;
        Name name = Names.ROOT.toTypeName();
        Symbol owner = Symbol.NONE;
        int flags = JAVA | PACKAGE | FINAL;
        int attrs = IS_ROOT;
        Symbol clasz = new ClassSymbol(owner, pos, flags, name, attrs);
        clasz.setInfo(global.getRootLoader());
        clasz.primaryConstructor().setInfo(
            Type.MethodType(Symbol.EMPTY_ARRAY, clasz.typeConstructor()));
        // !!! Type.MethodType(Symbol.EMPTY_ARRAY, clasz.thisType()));
        return clasz;
    }

    /** Creates the this-type symbol associated to this class. */
    private final Symbol newThisType() {
        return newTerm(pos, SYNTHETIC, Names.this_, IS_THISTYPE);
    }

    public Type thisType() {
        Global global = Global.instance;
        if (global.currentPhase.id > global.PHASE.ERASURE.id()) return type();
        return thistp;
    }

    public Type typeOfThis() {
        return thisSym.type();
    }

    public Symbol setTypeOfThis(Type tp) {
        thisSym = newThisType();
        thisSym.setInfo(tp);
        return this;
    }

    /** Return the next enclosing class */
    public Symbol enclClass() {
        return this;
    }

    public Symbol caseFieldAccessor(int index) {
        assert (flags & CASE) != 0 : this;
        Scope.SymbolIterator it = info().members().iterator();
        Symbol sym = null;
        if ((flags & JAVA) == 0) {
			for (int i = 0; i <= index; i++) {
				do {
					sym = it.next();
				} while (sym.kind != VAL || (sym.flags & CASEACCESSOR) == 0 || !sym.isMethod());
			}
			//System.out.println(this + ", case field[" + index + "] = " + sym);//DEBUG
		} else {
			sym = it.next();
			while ((sym.flags & SYNTHETIC) == 0) {
			    //System.out.println("skipping " + sym);
			    sym = it.next();
			}
			for (int i = 0; i < index; i++)
				sym = it.next();
			//System.out.println("field accessor = " + sym);//DEBUG
		}
		assert sym != null : this;
		return sym;
    }

    public final Symbol rebindSym() {
        return rebindSym;
    }

    public void reset(Type completer) {
        super.reset(completer);
        thisSym = this;
    }

    protected final TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
        assert !isModuleClass(): Debug.show(this);
        ClassSymbol clone = new ClassSymbol(owner, pos, flags, name, attrs);
        if (thisSym != this) clone.setTypeOfThis(typeOfThis());
        return clone;
    }

}

/**
 * A class for module class symbols
 *
 * @see Symbol#sourceModule()
 */
public final class ModuleClassSymbol extends ClassSymbol {

    /** The source module */
    private final ModuleSymbol module;

    /** Initializes this instance. */
    ModuleClassSymbol(ModuleSymbol module) {
        super(module.owner(), module.pos,
            (module.flags & MODULE2CLASSFLAGS) | MODUL | FINAL,
            module.name.toTypeName(), 0);
        primaryConstructor().flags |= PRIVATE;
        primaryConstructor().setInfo(
            Type.MethodType(Symbol.EMPTY_ARRAY, typeConstructor()));
        this.module = module;
    }

    public ModuleSymbol sourceModule() {
        return module;
    }

}

/**
 * A class for linked class symbols
 *
 * @see Symbol#linkedModule()
 */
final class LinkedClassSymbol extends ClassSymbol {

    /** The linked module */
    private final LinkedModuleSymbol module;

    /** Initializes this instance. */
    LinkedClassSymbol(Symbol owner, int flags, Name name) {
        super(owner, Position.NOPOS, flags, name, 0);
        this.module = new LinkedModuleSymbol(this);
    }

    public ModuleSymbol linkedModule() {
        return module;
    }

}

/** The class of Symbol.NONE
 */
final class NoSymbol extends Symbol {

    /** Constructor */
    public NoSymbol() {
        super(Kinds.NONE, null, Position.NOPOS, 0, Names.NOSYMBOL, 0);
        super.setInfo(Type.NoType);
    }

    /** Set type */
    public Symbol setInfo(Type info) {
        assert info == Type.NoType : info;
        return this;
    }

    /** Return the next enclosing class */
    public Symbol enclClass() {
        return this;
    }

    /** Return the next enclosing method */
    public Symbol enclMethod() {
        return this;
    }

    public Symbol owner() {
        throw new ApplicationError();
    }

    public Type thisType() {
        return Type.NoPrefix;
    }

    public void reset(Type completer) {
    }

    protected Symbol cloneSymbolImpl(Symbol owner, int attrs) {
        throw Debug.abort("illegal clone", this);
    }

}

/** An exception for signalling cyclic references.
 */
public class CyclicReference extends Type.Error {
    public Symbol sym;
    public Type info;
    public CyclicReference(Symbol sym, Type info) {
        super("illegal cyclic reference involving " + sym);
        this.sym = sym;
        this.info = info;
    }
}

/** A base class for values indexed by phases. */
abstract class IntervalList {

    /** Interval starts at start of phase "start" (inclusive) */
    public final Phase start;
    /** Interval ends at start of phase "limit" (inclusive) */
    private Phase limit;

    public IntervalList(IntervalList prev, Phase start) {
        this.start = start;
        this.limit = start;
        assert start != null && (prev == null || prev.limit.next == start) :
            Global.instance.currentPhase + " - " + prev + " - " + start;
    }

    public Phase limit() {
        return limit;
    }

    public void setLimit(Phase phase) {
        assert phase != null && !phase.precedes(start) : start + " - " + phase;
        limit = phase;
    }

    public String toString() {
        return "[" + start + "->" + limit + "]";
    }

}

/** A class for types indexed by phases. */
class TypeIntervalList extends IntervalList {

    /** Previous interval */
    public final TypeIntervalList prev;
    /** Info valid during this interval */
    public final Type info;

    public TypeIntervalList(TypeIntervalList prev, Type info, Phase start) {
        super(prev, start);
        this.prev = prev;
        this.info = info;
        assert info != null;
    }

}