Mercurial > projects > ddmd
comparison dmd/Type.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | 206db751bd4c |
children | 31c086f76669 |
comparison
equal
deleted
inserted
replaced
134:4251f96733f4 | 135:af1bebfd96a4 |
---|---|
57 import dmd.TRUST; | 57 import dmd.TRUST; |
58 import dmd.TemplateDeclaration; | 58 import dmd.TemplateDeclaration; |
59 import dmd.DotIdExp; | 59 import dmd.DotIdExp; |
60 import dmd.AggregateDeclaration; | 60 import dmd.AggregateDeclaration; |
61 import dmd.DotTemplateInstanceExp; | 61 import dmd.DotTemplateInstanceExp; |
62 import dmd.Token; | |
63 import dmd.TypeInfoWildDeclaration; | |
62 | 64 |
63 import dmd.expression.Util; | 65 import dmd.expression.Util; |
64 | 66 |
65 import dmd.backend.Symbol; | 67 import dmd.backend.Symbol; |
66 import dmd.backend.TYPE; | 68 import dmd.backend.TYPE; |
125 return templateIdentifierLookup(tident.ident, parameters); | 127 return templateIdentifierLookup(tident.ident, parameters); |
126 } | 128 } |
127 return -1; | 129 return -1; |
128 } | 130 } |
129 | 131 |
132 /*************************** | |
133 * Return !=0 if modfrom can be implicitly converted to modto | |
134 */ | |
135 int MODimplicitConv(MOD modfrom, MOD modto) | |
136 { | |
137 if (modfrom == modto) | |
138 return 1; | |
139 | |
140 //printf("MODimplicitConv(from = %x, to = %x)\n", modfrom, modto); | |
141 static uint X(MOD m, MOD n) | |
142 { | |
143 return (((m) << 4) | (n)); | |
144 } | |
145 switch (X(modfrom, modto)) | |
146 { | |
147 case X(MOD.MODundefined, MOD.MODconst): | |
148 case X(MOD.MODimmutable, MOD.MODconst): | |
149 case X(MOD.MODwild, MOD.MODconst): | |
150 case X(MOD.MODimmutable, MOD.MODconst | MOD.MODshared): | |
151 case X(MOD.MODshared, MOD.MODconst | MOD.MODshared): | |
152 case X(MOD.MODwild | MOD.MODshared, MOD.MODconst | MOD.MODshared): | |
153 return 1; | |
154 | |
155 default: | |
156 return 0; | |
157 } | |
158 } | |
159 | |
160 /********************************* | |
161 * Mangling for mod. | |
162 */ | |
163 void MODtoDecoBuffer(OutBuffer buf, MOD mod) | |
164 { | |
165 switch (mod) | |
166 { | |
167 case MOD.MODundefined: | |
168 break; | |
169 case MOD.MODconst: | |
170 buf.writeByte('x'); | |
171 break; | |
172 case MOD.MODimmutable: | |
173 buf.writeByte('y'); | |
174 break; | |
175 case MOD.MODshared: | |
176 buf.writeByte('O'); | |
177 break; | |
178 case MOD.MODshared | MOD.MODconst: | |
179 buf.writestring("Ox"); | |
180 break; | |
181 case MOD.MODwild: | |
182 buf.writestring("Ng"); | |
183 break; | |
184 case MOD.MODshared | MOD.MODwild: | |
185 buf.writestring("ONg"); | |
186 break; | |
187 default: | |
188 assert(0); | |
189 } | |
190 } | |
191 | |
192 /********************************* | |
193 * Name for mod. | |
194 */ | |
195 void MODtoBuffer(OutBuffer buf, MOD mod) | |
196 { | |
197 switch (mod) | |
198 { | |
199 case MOD.MODundefined: | |
200 break; | |
201 | |
202 case MOD.MODimmutable: | |
203 buf.writestring(Token.tochars[TOK.TOKimmutable]); | |
204 break; | |
205 | |
206 case MOD.MODshared: | |
207 buf.writestring(Token.tochars[TOK.TOKshared]); | |
208 break; | |
209 | |
210 case MOD.MODshared | MOD.MODconst: | |
211 buf.writestring(Token.tochars[TOK.TOKshared]); | |
212 buf.writeByte(' '); | |
213 case MOD.MODconst: | |
214 buf.writestring(Token.tochars[TOK.TOKconst]); | |
215 break; | |
216 | |
217 case MOD.MODshared | MOD.MODwild: | |
218 buf.writestring(Token.tochars[TOK.TOKshared]); | |
219 buf.writeByte(' '); | |
220 case MOD.MODwild: | |
221 buf.writestring(Token.tochars[TOKwild]); | |
222 break; | |
223 default: | |
224 assert(0); | |
225 } | |
226 } | |
227 | |
130 class Type | 228 class Type |
131 { | 229 { |
132 TY ty; | 230 TY ty; |
133 MOD mod; // modifiers MODxxxx | 231 MOD mod; // modifiers MODxxxx |
134 /* pick this order of numbers so switch statements work better | 232 /* pick this order of numbers so switch statements work better |
141 | 239 |
142 /* These are cached values that are lazily evaluated by constOf(), invariantOf(), etc. | 240 /* These are cached values that are lazily evaluated by constOf(), invariantOf(), etc. |
143 * They should not be referenced by anybody but mtype.c. | 241 * They should not be referenced by anybody but mtype.c. |
144 * They can be null if not lazily evaluated yet. | 242 * They can be null if not lazily evaluated yet. |
145 * Note that there is no "shared immutable", because that is just immutable | 243 * Note that there is no "shared immutable", because that is just immutable |
244 * Naked == no MOD bits | |
146 */ | 245 */ |
147 | 246 |
148 Type cto; // MODconst ? mutable version of this type : const version | 247 Type cto; // MODconst ? naked version of this type : const version |
149 Type ito; // MODinvariant ? mutable version of this type : invariant version | 248 Type ito; // MODimmutable ? naked version of this type : immutable version |
150 Type sto; // MODshared ? mutable version of this type : shared mutable version | 249 Type sto; // MODshared ? naked version of this type : shared mutable version |
151 Type scto; // MODshared|MODconst ? mutable version of this type : shared const version | 250 Type scto; // MODshared|MODconst ? naked version of this type : shared const version |
251 Type wto; // MODwild ? naked version of this type : wild version | |
252 Type swto; // MODshared|MODwild ? naked version of this type : shared wild version | |
253 | |
152 | 254 |
153 Type pto; // merged pointer to this type | 255 Type pto; // merged pointer to this type |
154 Type rto; // reference to this type | 256 Type rto; // reference to this type |
155 Type arrayof; // array of this type | 257 Type arrayof; // array of this type |
156 TypeInfoDeclaration vtinfo; // TypeInfo object for this Type | 258 TypeInfoDeclaration vtinfo; // TypeInfo object for this Type |
171 static ClassDeclaration typeinfodelegate; | 273 static ClassDeclaration typeinfodelegate; |
172 static ClassDeclaration typeinfotypelist; | 274 static ClassDeclaration typeinfotypelist; |
173 static ClassDeclaration typeinfoconst; | 275 static ClassDeclaration typeinfoconst; |
174 static ClassDeclaration typeinfoinvariant; | 276 static ClassDeclaration typeinfoinvariant; |
175 static ClassDeclaration typeinfoshared; | 277 static ClassDeclaration typeinfoshared; |
278 static ClassDeclaration typeinfowild; | |
176 | 279 |
177 static Type basic[TY.TMAX]; | 280 static Type basic[TY.TMAX]; |
178 static ubyte mangleChar[TY.TMAX]; | 281 static ubyte mangleChar[TY.TMAX]; |
179 static ubyte sizeTy[TY.TMAX]; | 282 static ubyte sizeTy[TY.TMAX]; |
180 static StringTable stringtable; | 283 static StringTable stringtable; |
491 /* If same class type, but t2n is const, then it's | 594 /* If same class type, but t2n is const, then it's |
492 * covariant. Do this test first because it can work on | 595 * covariant. Do this test first because it can work on |
493 * forward references. | 596 * forward references. |
494 */ | 597 */ |
495 if ((cast(TypeClass)t1n).sym == (cast(TypeClass)t2n).sym && | 598 if ((cast(TypeClass)t1n).sym == (cast(TypeClass)t2n).sym && |
496 t2n.mod == MOD.MODconst) | 599 MODimplicitConv(t1n.mod, t2n.mod)) |
497 goto Lcovariant; | 600 goto Lcovariant; |
498 | 601 |
499 // If t1n is forward referenced: | 602 // If t1n is forward referenced: |
500 ClassDeclaration cd = (cast(TypeClass)t1n).sym; | 603 ClassDeclaration cd = (cast(TypeClass)t1n).sym; |
501 if (!cd.baseClass && cd.baseclasses.dim && !cd.isInterfaceDeclaration()) | 604 if (!cd.baseClass && cd.baseclasses.dim && !cd.isInterfaceDeclaration()) |
510 goto Lnotcovariant; | 613 goto Lnotcovariant; |
511 | 614 |
512 Lcovariant: | 615 Lcovariant: |
513 /* Can convert mutable to const | 616 /* Can convert mutable to const |
514 */ | 617 */ |
618 if (!MODimplicitConv(t2.mod, t1.mod)) | |
619 goto Lnotcovariant; | |
620 static if(false) { | |
515 if (t1.mod != t2.mod) | 621 if (t1.mod != t2.mod) |
516 { | 622 { |
517 if (!(t1.mod & MOD.MODconst) && (t2.mod & MOD.MODconst)) | 623 if (!(t1.mod & MOD.MODconst) && (t2.mod & MOD.MODconst)) |
518 goto Lnotcovariant; | 624 goto Lnotcovariant; |
519 if (!(t1.mod & MOD.MODshared) && (t2.mod & MOD.MODshared)) | 625 if (!(t1.mod & MOD.MODshared) && (t2.mod & MOD.MODshared)) |
520 goto Lnotcovariant; | 626 goto Lnotcovariant; |
521 } | 627 } |
522 | 628 } |
523 /* Can convert pure to impure, and nothrow to throw | 629 /* Can convert pure to impure, and nothrow to throw |
524 */ | 630 */ |
525 if (!t1.ispure && t2.ispure) | 631 if (!t1.ispure && t2.ispure) |
526 goto Lnotcovariant; | 632 goto Lnotcovariant; |
527 | 633 |
626 mangleChar[TY.Tbool] = 'b'; | 732 mangleChar[TY.Tbool] = 'b'; |
627 mangleChar[TY.Tascii] = 'a'; | 733 mangleChar[TY.Tascii] = 'a'; |
628 mangleChar[TY.Twchar] = 'u'; | 734 mangleChar[TY.Twchar] = 'u'; |
629 mangleChar[TY.Tdchar] = 'w'; | 735 mangleChar[TY.Tdchar] = 'w'; |
630 | 736 |
737 // '@' shouldn't appear anywhere in the deco'd names | |
631 mangleChar[TY.Tbit] = '@'; | 738 mangleChar[TY.Tbit] = '@'; |
632 mangleChar[TY.Tinstance] = '@'; | 739 mangleChar[TY.Tinstance] = '@'; |
633 mangleChar[TY.Terror] = '@'; | 740 mangleChar[TY.Terror] = '@'; |
634 mangleChar[TY.Ttypeof] = '@'; | 741 mangleChar[TY.Ttypeof] = '@'; |
635 mangleChar[TY.Ttuple] = 'B'; | 742 mangleChar[TY.Ttuple] = 'B'; |
734 */ | 841 */ |
735 void toDecoBuffer(OutBuffer buf, int flag = 0) | 842 void toDecoBuffer(OutBuffer buf, int flag = 0) |
736 { | 843 { |
737 if (flag != mod && flag != 0x100) | 844 if (flag != mod && flag != 0x100) |
738 { | 845 { |
739 if (mod & MOD.MODshared) | 846 MODtoDecoBuffer(buf, mod); |
740 buf.writeByte('O'); | |
741 | |
742 if (mod & MOD.MODconst) | |
743 buf.writeByte('x'); | |
744 else if (mod & MOD.MODinvariant) | |
745 buf.writeByte('y'); | |
746 | |
747 // Cannot be both const and invariant | |
748 assert((mod & (MOD.MODconst | MOD.MODinvariant)) != (MOD.MODconst | MOD.MODinvariant)); | |
749 } | 847 } |
750 buf.writeByte(mangleChar[ty]); | 848 buf.writeByte(mangleChar[ty]); |
751 } | 849 } |
752 | 850 |
753 Type merge() | 851 Type merge() |
830 | 928 |
831 void toCBuffer3(OutBuffer buf, HdrGenState* hgs, MOD mod) | 929 void toCBuffer3(OutBuffer buf, HdrGenState* hgs, MOD mod) |
832 { | 930 { |
833 if (mod != this.mod) | 931 if (mod != this.mod) |
834 { | 932 { |
835 string p; | |
836 | |
837 if (this.mod & MOD.MODshared) | 933 if (this.mod & MOD.MODshared) |
838 buf.writestring("shared("); | 934 { |
839 | 935 MODtoBuffer(buf, this.mod & MOD.MODshared); |
840 switch (this.mod & (MOD.MODconst | MOD.MODinvariant)) | 936 buf.writeByte('('); |
841 { | 937 } |
842 case MOD.MODundefined: | 938 |
843 toCBuffer2(buf, hgs, this.mod); | 939 if (this.mod & ~MOD.MODshared) |
844 break; | 940 { |
845 case MOD.MODconst: | 941 MODtoBuffer(buf, this.mod & ~MOD.MODshared); |
846 p = "const("; | 942 buf.writeByte('('); |
847 goto L1; | 943 toCBuffer2(buf, hgs, this.mod); |
848 case MOD.MODinvariant: | 944 buf.writeByte(')'); |
849 p = "immutable("; | 945 } |
850 L1: buf.writestring(p); | 946 else |
851 toCBuffer2(buf, hgs, this.mod); | 947 toCBuffer2(buf, hgs, this.mod); |
852 buf.writeByte(')'); | 948 if (this.mod & MOD.MODshared) |
853 break; | 949 { |
854 } | 950 buf.writeByte(')'); |
855 | 951 } |
856 if (this.mod & MOD.MODshared) | |
857 buf.writeByte(')'); | |
858 } | 952 } |
859 } | 953 } |
860 | 954 |
861 void modToBuffer(OutBuffer buf) | 955 void modToBuffer(OutBuffer buf) |
862 { | 956 { |
863 if (mod & MOD.MODshared) | 957 if (mod) |
864 buf.writestring(" shared"); | 958 { |
865 if (mod & MOD.MODconst) | 959 buf.writeByte(' '); |
866 buf.writestring(" const"); | 960 MODtoBuffer(buf, mod); |
867 if (mod & MOD.MODinvariant) | 961 } |
868 buf.writestring(" immutable"); | |
869 } | 962 } |
870 | 963 |
871 version (CPP_MANGLE) { | 964 version (CPP_MANGLE) { |
872 void toCppMangle(OutBuffer buf, CppMangleState* cms) | 965 void toCppMangle(OutBuffer buf, CppMangleState* cms) |
873 { | 966 { |
946 s.checkDeprecated(loc, sc); | 1039 s.checkDeprecated(loc, sc); |
947 } | 1040 } |
948 | 1041 |
949 bool isConst() { return (mod & MOD.MODconst) != 0; } | 1042 bool isConst() { return (mod & MOD.MODconst) != 0; } |
950 | 1043 |
951 int isInvariant() { return mod & MOD.MODinvariant; } | 1044 int isImmutable() { return mod & MOD.MODimmutable; } |
952 | 1045 |
953 int isMutable() { return !(mod & (MOD.MODconst | MOD.MODinvariant)); } | 1046 int isMutable() { return !(mod & (MOD.MODconst | MOD.MODimmutable | MOD.MODwild)); } |
954 | 1047 |
955 int isShared() { return mod & MOD.MODshared; } | 1048 int isShared() { return mod & MOD.MODshared; } |
956 | 1049 |
957 int isSharedConst() { return mod == (MOD.MODshared | MOD.MODconst); } | 1050 int isSharedConst() { return mod == (MOD.MODshared | MOD.MODconst); } |
1051 | |
1052 int isWild() { return mod & MOD.MODwild; } | |
1053 | |
1054 int isSharedWild() { return mod == (MOD.MODshared | MOD.MODwild); } | |
1055 | |
1056 int isNaked() { return mod == 0; } | |
1057 | |
958 | 1058 |
959 /******************************** | 1059 /******************************** |
960 * Convert to 'const'. | 1060 * Convert to 'const'. |
961 */ | 1061 */ |
962 Type constOf() | 1062 Type constOf() |
980 * Convert to 'immutable'. | 1080 * Convert to 'immutable'. |
981 */ | 1081 */ |
982 Type invariantOf() | 1082 Type invariantOf() |
983 { | 1083 { |
984 //printf("Type.invariantOf() %p %s\n", this, toChars()); | 1084 //printf("Type.invariantOf() %p %s\n", this, toChars()); |
985 if (isInvariant()) | 1085 if (isImmutable()) |
986 { | 1086 { |
987 return this; | 1087 return this; |
988 } | 1088 } |
989 if (ito) | 1089 if (ito) |
990 { | 1090 { |
991 assert(ito.isInvariant()); | 1091 assert(ito.isImmutable()); |
992 return ito; | 1092 return ito; |
993 } | 1093 } |
994 Type t = makeInvariant(); | 1094 Type t = makeInvariant(); |
995 t = t.merge(); | 1095 t = t.merge(); |
996 t.fixTo(this); | 1096 t.fixTo(this); |
1005 if (isConst()) | 1105 if (isConst()) |
1006 { | 1106 { |
1007 if (isShared()) | 1107 if (isShared()) |
1008 t = sto; // shared const => shared | 1108 t = sto; // shared const => shared |
1009 else | 1109 else |
1010 t = cto; | 1110 t = cto; // const => naked |
1011 assert(!t || t.isMutable()); | 1111 assert(!t || t.isMutable()); |
1012 } | 1112 } |
1013 else if (isInvariant()) | 1113 else if (isImmutable()) |
1014 { | 1114 { |
1015 t = ito; | 1115 t = ito; |
1016 assert(!t || (t.isMutable() && !t.isShared())); | 1116 assert(!t || (t.isMutable() && !t.isShared())); |
1017 } | 1117 } |
1118 else if (isWild()) | |
1119 { | |
1120 if (isShared()) | |
1121 t = sto; // shared wild => shared | |
1122 else | |
1123 t = wto; // wild => naked | |
1124 assert(!t || t.isMutable()); | |
1125 } | |
1018 if (!t) | 1126 if (!t) |
1019 { | 1127 { |
1020 uint sz = this.classinfo.init.length; | 1128 t = makeMutable(); |
1021 t = cast(Type)GC.malloc(sz); | |
1022 memcpy(cast(void*)t, cast(void*)this, sz); | |
1023 t.mod = mod & MODshared; | |
1024 t.deco = null; | |
1025 t.arrayof = null; | |
1026 t.pto = null; | |
1027 t.rto = null; | |
1028 t.cto = null; | |
1029 t.ito = null; | |
1030 t.sto = null; | |
1031 t.scto = null; | |
1032 t.vtinfo = null; | |
1033 t = t.merge(); | 1129 t = t.merge(); |
1034 | |
1035 t.fixTo(this); | 1130 t.fixTo(this); |
1036 | 1131 } |
1037 switch (mod) | 1132 assert(t.isMutable()); |
1038 { | |
1039 case MODconst: | |
1040 t.cto = this; | |
1041 break; | |
1042 | |
1043 case MODinvariant: | |
1044 t.ito = this; | |
1045 break; | |
1046 | |
1047 case MODshared | MODconst: | |
1048 t.scto = this; | |
1049 break; | |
1050 | |
1051 default: | |
1052 assert(0); | |
1053 } | |
1054 } | |
1055 return t; | 1133 return t; |
1056 } | 1134 } |
1057 | 1135 |
1058 Type sharedOf() | 1136 Type sharedOf() |
1059 { | 1137 { |
1097 return t; | 1175 return t; |
1098 } | 1176 } |
1099 | 1177 |
1100 /******************************** | 1178 /******************************** |
1101 * Make type unshared. | 1179 * Make type unshared. |
1180 * 0 => 0 | |
1181 * const => const | |
1182 * immutable => immutable | |
1183 * shared => 0 | |
1184 * shared const => const | |
1185 * wild => wild | |
1186 * shared wild => wild | |
1102 */ | 1187 */ |
1103 Type unSharedOf() | 1188 Type unSharedOf() |
1104 { | 1189 { |
1105 //writef("Type::unSharedOf() %p, %s\n", this, toChars()); | 1190 //writef("Type::unSharedOf() %p, %s\n", this, toChars()); |
1106 Type t = this; | 1191 Type t = this; |
1107 | 1192 |
1108 if (isShared()) | 1193 if (isShared()) |
1109 { | 1194 { |
1110 if (isConst()) | 1195 if (isConst()) |
1111 t = cto; // shared const => const | 1196 t = cto; // shared const => const |
1197 else if (isWild()) | |
1198 t = wto; // shared wild => wild | |
1112 else | 1199 else |
1113 t = sto; | 1200 t = sto; |
1114 assert(!t || !t.isShared()); | 1201 assert(!t || !t.isShared()); |
1115 } | 1202 } |
1116 | 1203 |
1126 t.rto = null; | 1213 t.rto = null; |
1127 t.cto = null; | 1214 t.cto = null; |
1128 t.ito = null; | 1215 t.ito = null; |
1129 t.sto = null; | 1216 t.sto = null; |
1130 t.scto = null; | 1217 t.scto = null; |
1218 t.wto = null; | |
1219 t.swto = null; | |
1131 t.vtinfo = null; | 1220 t.vtinfo = null; |
1132 t = t.merge(); | 1221 t = t.merge(); |
1133 | 1222 |
1134 t.fixTo(this); | 1223 t.fixTo(this); |
1135 | |
1136 switch (mod) | |
1137 { | |
1138 case MODshared: | |
1139 t.sto = this; | |
1140 break; | |
1141 | |
1142 case MODshared | MODconst: | |
1143 t.scto = this; | |
1144 break; | |
1145 | |
1146 default: | |
1147 assert(0); | |
1148 } | |
1149 } | 1224 } |
1150 assert(!t.isShared()); | 1225 assert(!t.isShared()); |
1151 return t; | 1226 return t; |
1152 } | 1227 } |
1153 | 1228 |
1229 | |
1230 /******************************** | |
1231 * Convert to 'wild'. | |
1232 */ | |
1233 | |
1234 Type wildOf() | |
1235 { | |
1236 //printf("Type::wildOf() %p %s\n", this, toChars()); | |
1237 if (mod == MOD.MODwild) | |
1238 { | |
1239 return this; | |
1240 } | |
1241 if (wto) | |
1242 { | |
1243 assert(wto.isWild()); | |
1244 return wto; | |
1245 } | |
1246 Type t = makeWild(); | |
1247 t = t.merge(); | |
1248 t.fixTo(this); | |
1249 //printf("\t%p %s\n", t, t->toChars()); | |
1250 return t; | |
1251 } | |
1252 | |
1253 Type sharedWildOf() | |
1254 { | |
1255 //printf("Type::sharedWildOf() %p, %s\n", this, toChars()); | |
1256 if (mod == (MOD.MODwild)) | |
1257 { | |
1258 return this; | |
1259 } | |
1260 if (swto) | |
1261 { | |
1262 assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1263 return swto; | |
1264 } | |
1265 Type t = makeSharedWild(); | |
1266 t = t.merge(); | |
1267 t.fixTo(this); | |
1268 //printf("\t%p\n", t); | |
1269 return t; | |
1270 } | |
1271 | |
1154 static uint X(MOD m, MOD n) | 1272 static uint X(MOD m, MOD n) |
1155 { | 1273 { |
1156 return (((m) << 3) | (n)); | 1274 return (((m) << 4) | (n)); |
1157 } | 1275 } |
1158 | 1276 |
1159 /********************************** | 1277 /********************************** |
1160 * For our new type 'this', which is type-constructed from t, | 1278 * For our new type 'this', which is type-constructed from t, |
1161 * fill in the cto, ito, sto, scto shortcuts. | 1279 * fill in the cto, ito, sto, scto, wto shortcuts. |
1162 */ | 1280 */ |
1163 void fixTo(Type t) | 1281 void fixTo(Type t) |
1164 { | 1282 { |
1165 ito = t.ito; | 1283 ito = t.ito; |
1166 static if (false) { | 1284 static if (false) { |
1179 { | 1297 { |
1180 case X(MOD.MODundefined, MOD.MODconst): | 1298 case X(MOD.MODundefined, MOD.MODconst): |
1181 cto = t; | 1299 cto = t; |
1182 break; | 1300 break; |
1183 | 1301 |
1184 case X(MOD.MODundefined, MOD.MODinvariant): | 1302 case X(MOD.MODundefined, MOD.MODimmutable): |
1185 ito = t; | 1303 ito = t; |
1186 break; | 1304 break; |
1187 | 1305 |
1188 case X(MOD.MODundefined, MOD.MODshared): | 1306 case X(MOD.MODundefined, MOD.MODshared): |
1189 sto = t; | 1307 sto = t; |
1191 | 1309 |
1192 case X(MOD.MODundefined, MOD.MODshared | MOD.MODconst): | 1310 case X(MOD.MODundefined, MOD.MODshared | MOD.MODconst): |
1193 scto = t; | 1311 scto = t; |
1194 break; | 1312 break; |
1195 | 1313 |
1314 case X(MOD.MODundefined, MODwild): | |
1315 wto = t; | |
1316 break; | |
1317 | |
1318 case X(MOD.MODundefined, MODshared | MODwild): | |
1319 swto = t; | |
1320 break; | |
1321 | |
1196 | 1322 |
1197 case X(MOD.MODconst, MOD.MODundefined): | 1323 case X(MOD.MODconst, MOD.MODundefined): |
1198 cto = null; | 1324 cto = null; |
1199 goto L2; | 1325 goto L2; |
1200 | 1326 |
1201 case X(MOD.MODconst, MOD.MODinvariant): | 1327 case X(MOD.MODconst, MOD.MODimmutable): |
1202 ito = t; | 1328 ito = t; |
1203 goto L2; | 1329 goto L2; |
1204 | 1330 |
1205 case X(MOD.MODconst, MOD.MODshared): | 1331 case X(MOD.MODconst, MOD.MODshared): |
1206 sto = t; | 1332 sto = t; |
1207 goto L2; | 1333 goto L2; |
1208 | 1334 |
1209 case X(MOD.MODconst, MOD.MODshared | MOD.MODconst): | 1335 case X(MOD.MODconst, MOD.MODshared | MOD.MODconst): |
1210 scto = t; | 1336 scto = t; |
1337 goto L2; | |
1338 | |
1339 case X(MOD.MODconst, MOD.MODwild): | |
1340 wto = t; | |
1341 goto L2; | |
1342 | |
1343 case X(MOD.MODconst, MOD.MODshared | MOD.MODwild): | |
1344 swto = t; | |
1211 L2: | 1345 L2: |
1212 t.cto = this; | 1346 t.cto = this; |
1213 break; | 1347 break; |
1214 | 1348 |
1215 | 1349 |
1216 case X(MOD.MODinvariant, MOD.MODundefined): | 1350 case X(MOD.MODimmutable, MOD.MODundefined): |
1217 ito = null; | 1351 ito = null; |
1218 goto L3; | 1352 goto L3; |
1219 | 1353 |
1220 case X(MOD.MODinvariant, MOD.MODconst): | 1354 case X(MOD.MODimmutable, MOD.MODconst): |
1221 cto = t; | 1355 cto = t; |
1222 goto L3; | 1356 goto L3; |
1223 | 1357 |
1224 case X(MOD.MODinvariant, MOD.MODshared): | 1358 case X(MOD.MODimmutable, MOD.MODshared): |
1225 sto = t; | 1359 sto = t; |
1226 goto L3; | 1360 goto L3; |
1227 | 1361 |
1228 case X(MOD.MODinvariant, MOD.MODshared | MOD.MODconst): | 1362 case X(MOD.MODimmutable, MOD.MODshared | MOD.MODconst): |
1229 scto = t; | 1363 scto = t; |
1364 goto L3; | |
1365 | |
1366 case X(MOD.MODimmutable, MOD.MODwild): | |
1367 wto = t; | |
1368 goto L3; | |
1369 | |
1370 case X(MOD.MODimmutable, MOD.MODshared | MOD.MODwild): | |
1371 swto = t; | |
1230 L3: | 1372 L3: |
1231 t.ito = this; | 1373 t.ito = this; |
1232 if (t.cto) t.cto.ito = this; | 1374 if (t.cto) t.cto.ito = this; |
1233 if (t.sto) t.sto.ito = this; | 1375 if (t.sto) t.sto.ito = this; |
1234 if (t.scto) t.scto.ito = this; | 1376 if (t.scto) t.scto.ito = this; |
1377 if (t.wto) t.wto.ito = this; | |
1378 if (t.swto) t.swto.ito = this; | |
1235 break; | 1379 break; |
1236 | 1380 |
1237 | 1381 |
1238 case X(MOD.MODshared, MOD.MODundefined): | 1382 case X(MOD.MODshared, MOD.MODundefined): |
1239 sto = null; | 1383 sto = null; |
1241 | 1385 |
1242 case X(MOD.MODshared, MOD.MODconst): | 1386 case X(MOD.MODshared, MOD.MODconst): |
1243 cto = t; | 1387 cto = t; |
1244 goto L4; | 1388 goto L4; |
1245 | 1389 |
1246 case X(MOD.MODshared, MOD.MODinvariant): | 1390 case X(MOD.MODshared, MOD.MODimmutable): |
1247 ito = t; | 1391 ito = t; |
1248 goto L4; | 1392 goto L4; |
1249 | 1393 |
1250 case X(MOD.MODshared, MOD.MODshared | MOD.MODconst): | 1394 case X(MOD.MODshared, MOD.MODshared | MOD.MODconst): |
1251 scto = t; | 1395 scto = t; |
1396 goto L4; | |
1397 | |
1398 case X(MOD.MODshared, MOD.MODwild): | |
1399 wto = t; | |
1400 goto L4; | |
1401 | |
1402 case X(MOD.MODshared, MOD.MODshared | MOD.MODwild): | |
1403 swto = t; | |
1252 L4: | 1404 L4: |
1253 t.sto = this; | 1405 t.sto = this; |
1254 break; | 1406 break; |
1255 | 1407 |
1256 | 1408 |
1257 case X(MOD.MODshared | MOD.MODconst, MOD.MODundefined): | 1409 case X(MOD.MODshared | MOD.MODconst, MOD.MODundefined): |
1258 scto = null; | 1410 scto = null; |
1259 break; | 1411 goto L5; |
1260 | 1412 |
1261 case X(MOD.MODshared | MOD.MODconst, MOD.MODconst): | 1413 case X(MOD.MODshared | MOD.MODconst, MOD.MODconst): |
1262 cto = t; | 1414 cto = t; |
1263 break; | 1415 goto L5; |
1264 | 1416 |
1265 case X(MOD.MODshared | MOD.MODconst, MOD.MODinvariant): | 1417 case X(MOD.MODshared | MOD.MODconst, MOD.MODimmutable): |
1266 ito = t; | 1418 ito = t; |
1267 break; | 1419 goto L5; |
1420 | |
1421 case X(MOD.MODshared | MOD.MODconst, MOD.MODwild): | |
1422 wto = t; | |
1423 goto L5; | |
1268 | 1424 |
1269 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared): | 1425 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared): |
1270 sto = t; | 1426 sto = t; |
1427 goto L5; | |
1428 | |
1429 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared | MOD.MODwild): | |
1430 swto = t; | |
1271 L5: | 1431 L5: |
1272 t.scto = this; | 1432 t.scto = this; |
1273 break; | 1433 break; |
1434 | |
1435 case X(MOD.MODwild, MOD.MODundefined): | |
1436 wto = null; | |
1437 goto L6; | |
1438 | |
1439 case X(MOD.MODwild, MOD.MODconst): | |
1440 cto = t; | |
1441 goto L6; | |
1442 | |
1443 case X(MOD.MODwild, MOD.MODimmutable): | |
1444 ito = t; | |
1445 goto L6; | |
1446 | |
1447 case X(MOD.MODwild, MOD.MODshared): | |
1448 sto = t; | |
1449 goto L6; | |
1450 | |
1451 case X(MOD.MODwild, MOD.MODshared | MOD.MODconst): | |
1452 scto = t; | |
1453 goto L6; | |
1454 | |
1455 case X(MOD.MODwild, MOD.MODshared | MOD.MODwild): | |
1456 swto = t; | |
1457 L6: | |
1458 t.wto = this; | |
1459 break; | |
1460 | |
1461 | |
1462 case X(MOD.MODshared | MOD.MODwild, MOD.MODundefined): | |
1463 swto = null; | |
1464 goto L7; | |
1465 | |
1466 case X(MOD.MODshared | MOD.MODwild, MOD.MODconst): | |
1467 cto = t; | |
1468 goto L7; | |
1469 | |
1470 case X(MOD.MODshared | MOD.MODwild, MOD.MODimmutable): | |
1471 ito = t; | |
1472 goto L7; | |
1473 | |
1474 case X(MOD.MODshared | MOD.MODwild, MOD.MODshared): | |
1475 sto = t; | |
1476 goto L7; | |
1477 | |
1478 case X(MOD.MODshared | MOD.MODwild, MOD.MODshared | MOD.MODconst): | |
1479 scto = t; | |
1480 goto L7; | |
1481 | |
1482 case X(MOD.MODshared | MOD.MODwild, MOD.MODwild): | |
1483 wto = t; | |
1484 L7: | |
1485 t.swto = this; | |
1486 break; | |
1274 } | 1487 } |
1275 | 1488 |
1276 check(); | 1489 check(); |
1277 t.check(); | 1490 t.check(); |
1278 //printf("fixTo: %s, %s\n", toChars(), t.toChars()); | 1491 //printf("fixTo: %s, %s\n", toChars(), t.toChars()); |
1285 { | 1498 { |
1286 switch (mod) | 1499 switch (mod) |
1287 { | 1500 { |
1288 case MOD.MODundefined: | 1501 case MOD.MODundefined: |
1289 if (cto) assert(cto.mod == MOD.MODconst); | 1502 if (cto) assert(cto.mod == MOD.MODconst); |
1290 if (ito) assert(ito.mod == MOD.MODinvariant); | 1503 if (ito) assert(ito.mod == MOD.MODimmutable); |
1291 if (sto) assert(sto.mod == MOD.MODshared); | 1504 if (sto) assert(sto.mod == MOD.MODshared); |
1292 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | 1505 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); |
1506 if (wto) assert(wto.mod == MOD.MODwild); | |
1507 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1293 break; | 1508 break; |
1294 | 1509 |
1295 case MOD.MODconst: | 1510 case MOD.MODconst: |
1296 if (cto) assert(cto.mod == MOD.MODundefined); | 1511 if (cto) assert(cto.mod == MOD.MODundefined); |
1297 if (ito) assert(ito.mod == MOD.MODinvariant); | 1512 if (ito) assert(ito.mod == MOD.MODimmutable); |
1298 if (sto) assert(sto.mod == MOD.MODshared); | 1513 if (sto) assert(sto.mod == MOD.MODshared); |
1299 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | 1514 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); |
1515 if (wto) assert(wto.mod == MOD.MODwild); | |
1516 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1300 break; | 1517 break; |
1301 | 1518 |
1302 case MOD.MODinvariant: | 1519 case MOD.MODimmutable: |
1303 if (cto) assert(cto.mod == MOD.MODconst); | 1520 if (cto) assert(cto.mod == MOD.MODconst); |
1304 if (ito) assert(ito.mod == MOD.MODundefined); | 1521 if (ito) assert(ito.mod == MOD.MODundefined); |
1305 if (sto) assert(sto.mod == MOD.MODshared); | 1522 if (sto) assert(sto.mod == MOD.MODshared); |
1306 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | 1523 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); |
1524 if (wto) assert(wto.mod == MOD.MODwild); | |
1525 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1307 break; | 1526 break; |
1308 | 1527 |
1309 case MOD.MODshared: | 1528 case MOD.MODshared: |
1310 if (cto) assert(cto.mod == MOD.MODconst); | 1529 if (cto) assert(cto.mod == MOD.MODconst); |
1311 if (ito) assert(ito.mod == MOD.MODinvariant); | 1530 if (ito) assert(ito.mod == MOD.MODimmutable); |
1312 if (sto) assert(sto.mod == MOD.MODundefined); | 1531 if (sto) assert(sto.mod == MOD.MODundefined); |
1313 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | 1532 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); |
1533 if (wto) assert(wto.mod == MOD.MODwild); | |
1534 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1314 break; | 1535 break; |
1315 | 1536 |
1316 case MOD.MODshared | MOD.MODconst: | 1537 case MOD.MODshared | MOD.MODconst: |
1317 if (cto) assert(cto.mod == MOD.MODconst); | 1538 if (cto) assert(cto.mod == MOD.MODconst); |
1318 if (ito) assert(ito.mod == MOD.MODinvariant); | 1539 if (ito) assert(ito.mod == MOD.MODimmutable); |
1319 if (sto) assert(sto.mod == MOD.MODshared); | 1540 if (sto) assert(sto.mod == MOD.MODshared); |
1320 if (scto) assert(scto.mod == MOD.MODundefined); | 1541 if (scto) assert(scto.mod == MOD.MODundefined); |
1542 if (wto) assert(wto.mod == MOD.MODwild); | |
1543 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1321 break; | 1544 break; |
1545 | |
1546 case MOD.MODwild: | |
1547 if (cto) assert(cto.mod == MOD.MODconst); | |
1548 if (ito) assert(ito.mod == MOD.MODimmutable); | |
1549 if (sto) assert(sto.mod == MOD.MODshared); | |
1550 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1551 if (wto) assert(wto.mod == MOD.MODundefined); | |
1552 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1553 break; | |
1554 | |
1555 case MOD.MODshared | MOD.MODwild: | |
1556 if (cto) assert(cto.mod == MOD.MODconst); | |
1557 if (ito) assert(ito.mod == MOD.MODimmutable); | |
1558 if (sto) assert(sto.mod == MOD.MODshared); | |
1559 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1560 if (wto) assert(wto.mod == MOD.MODwild); | |
1561 if (swto) assert(swto.mod == MOD.MODundefined); | |
1562 break; | |
1322 } | 1563 } |
1323 | 1564 |
1324 Type tn = nextOf(); | 1565 Type tn = nextOf(); |
1325 if (tn && ty != TY.Tfunction && ty != TY.Tdelegate) | 1566 if (tn && ty != TY.Tfunction && ty != TY.Tdelegate) |
1326 { | 1567 { |
1329 { | 1570 { |
1330 case MOD.MODundefined: | 1571 case MOD.MODundefined: |
1331 break; | 1572 break; |
1332 | 1573 |
1333 case MOD.MODconst: | 1574 case MOD.MODconst: |
1334 assert(tn.mod & MOD.MODinvariant || tn.mod & MOD.MODconst); | 1575 assert(tn.mod & MOD.MODimmutable || tn.mod & MOD.MODconst); |
1335 break; | 1576 break; |
1336 | 1577 |
1337 case MOD.MODinvariant: | 1578 case MOD.MODimmutable: |
1338 assert(tn.mod == MOD.MODinvariant); | 1579 assert(tn.mod == MOD.MODimmutable); |
1339 break; | 1580 break; |
1340 | 1581 |
1341 case MOD.MODshared: | 1582 case MOD.MODshared: |
1342 assert(tn.mod & MOD.MODinvariant || tn.mod & MOD.MODshared); | 1583 assert(tn.mod & MOD.MODimmutable || tn.mod & MOD.MODshared); |
1343 break; | 1584 break; |
1344 | 1585 |
1345 case MOD.MODshared | MOD.MODconst: | 1586 case MOD.MODshared | MOD.MODconst: |
1346 assert(tn.mod & MOD.MODinvariant || tn.mod & (MOD.MODshared | MOD.MODconst)); | 1587 assert(tn.mod & MOD.MODimmutable || tn.mod & (MOD.MODshared | MOD.MODconst)); |
1588 break; | |
1589 | |
1590 case MOD.MODwild: | |
1591 assert(tn.mod); | |
1592 break; | |
1593 | |
1594 case MOD.MODshared | MOD.MODwild: | |
1595 assert(tn.mod == MOD.MODimmutable || tn.mod == (MOD.MODshared | MOD.MODconst) || tn.mod == (MOD.MODshared | MOD.MODwild)); | |
1347 break; | 1596 break; |
1348 } | 1597 } |
1349 tn.check(); | 1598 tn.check(); |
1350 } | 1599 } |
1351 } | 1600 } |
1358 Type t; | 1607 Type t; |
1359 | 1608 |
1360 switch (mod) | 1609 switch (mod) |
1361 { | 1610 { |
1362 case 0: | 1611 case 0: |
1363 t = mutableOf(); | 1612 t = unSharedOf().mutableOf(); |
1364 break; | 1613 break; |
1365 | 1614 |
1366 case MODconst: | 1615 case MODconst: |
1367 t = constOf(); | 1616 t = unSharedOf().constOf(); |
1368 break; | 1617 break; |
1369 | 1618 |
1370 case MODinvariant: | 1619 case MODimmutable: |
1371 t = invariantOf(); | 1620 t = invariantOf(); |
1372 break; | 1621 break; |
1373 | 1622 |
1374 case MODshared: | 1623 case MODshared: |
1375 t = sharedOf(); | 1624 t = mutableOf().sharedOf(); |
1376 break; | 1625 break; |
1377 | 1626 |
1378 case MODshared | MODconst: | 1627 case MODshared | MODconst: |
1379 t = sharedConstOf(); | 1628 t = sharedConstOf(); |
1629 break; | |
1630 | |
1631 case MODwild: | |
1632 t = unSharedOf().wildOf(); | |
1633 break; | |
1634 | |
1635 case MODshared | MODwild: | |
1636 t = sharedWildOf(); | |
1380 break; | 1637 break; |
1381 | 1638 |
1382 default: | 1639 default: |
1383 assert(0); | 1640 assert(0); |
1384 } | 1641 } |
1394 { | 1651 { |
1395 Type t = this; | 1652 Type t = this; |
1396 | 1653 |
1397 /* Add anything to immutable, and it remains immutable | 1654 /* Add anything to immutable, and it remains immutable |
1398 */ | 1655 */ |
1399 if (!t.isInvariant()) | 1656 //printf("addMod(%x) %s\n", mod, toChars()); |
1657 if (!t.isImmutable()) | |
1400 { | 1658 { |
1401 switch (mod) | 1659 switch (mod) |
1402 { | 1660 { |
1403 case MOD.MODundefined: | 1661 case MOD.MODundefined: |
1404 break; | 1662 break; |
1408 t = sharedConstOf(); | 1666 t = sharedConstOf(); |
1409 else | 1667 else |
1410 t = constOf(); | 1668 t = constOf(); |
1411 break; | 1669 break; |
1412 | 1670 |
1413 case MOD.MODinvariant: | 1671 case MOD.MODimmutable: |
1414 t = invariantOf(); | 1672 t = invariantOf(); |
1415 break; | 1673 break; |
1416 | 1674 |
1417 case MOD.MODshared: | 1675 case MOD.MODshared: |
1418 if (isConst()) | 1676 if (isConst()) |
1419 t = sharedConstOf(); | 1677 t = sharedConstOf(); |
1678 else if (isWild()) | |
1679 t = sharedWildOf(); | |
1420 else | 1680 else |
1421 t = sharedOf(); | 1681 t = sharedOf(); |
1422 break; | 1682 break; |
1423 | 1683 |
1424 case MOD.MODshared | MOD.MODconst: | 1684 case MOD.MODshared | MOD.MODconst: |
1425 t = sharedConstOf(); | 1685 t = sharedConstOf(); |
1426 break; | 1686 break; |
1687 | |
1688 case MOD.MODwild: | |
1689 if (isConst()) | |
1690 {} | |
1691 else if (isShared()) | |
1692 t = sharedWildOf(); | |
1693 else | |
1694 t = wildOf(); | |
1695 break; | |
1696 | |
1697 case MOD.MODshared | MOD.MODwild: | |
1698 t = sharedWildOf(); | |
1699 break; | |
1427 } | 1700 } |
1428 } | 1701 } |
1429 return t; | 1702 return t; |
1430 } | 1703 } |
1431 | 1704 |
1434 /* Just translate to MOD bits and let addMod() do the work | 1707 /* Just translate to MOD bits and let addMod() do the work |
1435 */ | 1708 */ |
1436 MOD mod = MOD.MODundefined; | 1709 MOD mod = MOD.MODundefined; |
1437 | 1710 |
1438 if (stc & STC.STCimmutable) | 1711 if (stc & STC.STCimmutable) |
1439 mod = MOD.MODinvariant; | 1712 mod = MOD.MODimmutable; |
1440 else | 1713 else |
1441 { | 1714 { |
1442 if (stc & (STC.STCconst | STC.STCin)) | 1715 if (stc & (STC.STCconst | STC.STCin)) |
1443 mod = MOD.MODconst; | 1716 mod = MOD.MODconst; |
1444 if (stc & STC.STCshared) | 1717 if (stc & STC.STCshared) |
1445 mod |= MOD.MODshared; | 1718 mod |= MOD.MODshared; |
1719 if (stc & STC.STCwild) | |
1720 mod |= MOD.MODwild; | |
1446 } | 1721 } |
1447 | 1722 |
1448 return addMod(mod); | 1723 return addMod(mod); |
1449 } | 1724 } |
1450 | 1725 |
1512 t.rto = null; | 1787 t.rto = null; |
1513 t.cto = null; | 1788 t.cto = null; |
1514 t.ito = null; | 1789 t.ito = null; |
1515 t.sto = null; | 1790 t.sto = null; |
1516 t.scto = null; | 1791 t.scto = null; |
1792 t.wto = null; | |
1793 t.swto = null; | |
1517 t.vtinfo = null; | 1794 t.vtinfo = null; |
1518 | 1795 |
1519 //printf("-Type.makeConst() %p, %s\n", t, toChars()); | 1796 //printf("-Type.makeConst() %p, %s\n", t, toChars()); |
1520 return t; | 1797 return t; |
1521 } | 1798 } |
1525 if (ito) { | 1802 if (ito) { |
1526 return ito; | 1803 return ito; |
1527 } | 1804 } |
1528 | 1805 |
1529 Type t = clone(); | 1806 Type t = clone(); |
1530 t.mod = MOD.MODinvariant; | 1807 t.mod = MOD.MODimmutable; |
1531 | 1808 |
1532 t.deco = null; | 1809 t.deco = null; |
1533 t.arrayof = null; | 1810 t.arrayof = null; |
1534 t.pto = null; | 1811 t.pto = null; |
1535 t.rto = null; | 1812 t.rto = null; |
1536 t.cto = null; | 1813 t.cto = null; |
1537 t.ito = null; | 1814 t.ito = null; |
1538 t.sto = null; | 1815 t.sto = null; |
1539 t.scto = null; | 1816 t.scto = null; |
1817 t.wto = null; | |
1818 t.swto = null; | |
1540 t.vtinfo = null; | 1819 t.vtinfo = null; |
1541 | 1820 |
1542 return t; | 1821 return t; |
1543 } | 1822 } |
1544 | 1823 |
1556 t.rto = null; | 1835 t.rto = null; |
1557 t.cto = null; | 1836 t.cto = null; |
1558 t.ito = null; | 1837 t.ito = null; |
1559 t.sto = null; | 1838 t.sto = null; |
1560 t.scto = null; | 1839 t.scto = null; |
1840 t.wto = null; | |
1841 t.swto = null; | |
1561 t.vtinfo = null; | 1842 t.vtinfo = null; |
1562 | 1843 |
1563 return t; | 1844 return t; |
1564 } | 1845 } |
1565 | 1846 |
1577 t.rto = null; | 1858 t.rto = null; |
1578 t.cto = null; | 1859 t.cto = null; |
1579 t.ito = null; | 1860 t.ito = null; |
1580 t.sto = null; | 1861 t.sto = null; |
1581 t.scto = null; | 1862 t.scto = null; |
1863 t.wto = null; | |
1864 t.swto = null; | |
1582 t.vtinfo = null; | 1865 t.vtinfo = null; |
1583 | 1866 |
1584 return t; | 1867 return t; |
1585 } | 1868 } |
1586 | 1869 |
1870 Type makeWild() | |
1871 { | |
1872 if (wto) | |
1873 return wto; | |
1874 | |
1875 Type t = clone(); | |
1876 t.mod = MOD.MODwild; | |
1877 t.deco = null; | |
1878 t.arrayof = null; | |
1879 t.pto = null; | |
1880 t.rto = null; | |
1881 t.cto = null; | |
1882 t.ito = null; | |
1883 t.sto = null; | |
1884 t.scto = null; | |
1885 t.wto = null; | |
1886 t.swto = null; | |
1887 t.vtinfo = null; | |
1888 return t; | |
1889 } | |
1890 | |
1891 Type makeSharedWild() | |
1892 { | |
1893 if (swto) | |
1894 return swto; | |
1895 | |
1896 Type t = clone(); | |
1897 t.mod = MOD.MODshared | MOD.MODwild; | |
1898 t.deco = null; | |
1899 t.arrayof = null; | |
1900 t.pto = null; | |
1901 t.rto = null; | |
1902 t.cto = null; | |
1903 t.ito = null; | |
1904 t.sto = null; | |
1905 t.scto = null; | |
1906 t.wto = null; | |
1907 t.swto = null; | |
1908 t.vtinfo = null; | |
1909 return t; | |
1910 } | |
1911 | |
1912 Type makeMutable() | |
1913 { | |
1914 Type t = clone(); | |
1915 t.mod = mod & MOD.MODshared; | |
1916 t.deco = null; | |
1917 t.arrayof = null; | |
1918 t.pto = null; | |
1919 t.rto = null; | |
1920 t.cto = null; | |
1921 t.ito = null; | |
1922 t.sto = null; | |
1923 t.scto = null; | |
1924 t.wto = null; | |
1925 t.swto = null; | |
1926 t.vtinfo = null; | |
1927 return t; | |
1928 } | |
1929 | |
1587 Dsymbol toDsymbol(Scope sc) | 1930 Dsymbol toDsymbol(Scope sc) |
1588 { | 1931 { |
1589 return null; | 1932 return null; |
1590 } | 1933 } |
1591 | 1934 |
1625 */ | 1968 */ |
1626 MATCH constConv(Type to) | 1969 MATCH constConv(Type to) |
1627 { | 1970 { |
1628 if (equals(to)) | 1971 if (equals(to)) |
1629 return MATCH.MATCHexact; | 1972 return MATCH.MATCHexact; |
1630 if (ty == to.ty && to.mod == MOD.MODconst) | 1973 if (ty == to.ty && MODimplicitConv(mod, to.mod)) |
1631 return MATCH.MATCHconst; | 1974 return MATCH.MATCHconst; |
1632 return MATCH.MATCHnomatch; | 1975 return MATCH.MATCHnomatch; |
1633 } | 1976 } |
1634 | 1977 |
1635 /******************************** | 1978 /******************************** |
1881 Expression defaultInit(Loc loc) | 2224 Expression defaultInit(Loc loc) |
1882 { | 2225 { |
1883 assert(false); | 2226 assert(false); |
1884 } | 2227 } |
1885 | 2228 |
2229 /*************************************** | |
2230 * Use when we prefer the default initializer to be a literal, | |
2231 * rather than a global immutable variable. | |
2232 */ | |
2233 Expression defaultInitLiteral(Loc loc = Loc(0)) | |
2234 { | |
2235 version(LOGDEFAULTINIT) { | |
2236 printf("Type::defaultInitLiteral() '%s'\n", toChars()); | |
2237 } | |
2238 return defaultInit(loc); | |
2239 } | |
2240 | |
1886 ///bool isZeroInit(Loc loc = Loc(0)) // if initializer is 0 | 2241 ///bool isZeroInit(Loc loc = Loc(0)) // if initializer is 0 |
1887 bool isZeroInit(Loc loc) // if initializer is 0 | 2242 bool isZeroInit(Loc loc) // if initializer is 0 |
1888 { | 2243 { |
1889 assert(false); | 2244 assert(false); |
1890 } | 2245 } |
1993 goto Lnomatch; | 2348 goto Lnomatch; |
1994 Type tt = this; | 2349 Type tt = this; |
1995 Type at = cast(Type)dedtypes[i]; | 2350 Type at = cast(Type)dedtypes[i]; |
1996 | 2351 |
1997 // 5*5 == 25 cases | 2352 // 5*5 == 25 cases |
1998 static pure int X(int U, int T) { return ((U << 3) | T); } | 2353 static pure int X(int U, int T) { return ((U << 4) | T); } |
1999 | 2354 |
2000 switch (X(tparam.mod, mod)) | 2355 switch (X(tparam.mod, mod)) |
2001 { | 2356 { |
2002 case X(0, 0): | 2357 case X(0, 0): |
2003 case X(0, MODconst): | 2358 case X(0, MODconst): |
2004 case X(0, MODinvariant): | 2359 case X(0, MODimmutable): |
2005 case X(0, MODshared): | 2360 case X(0, MODshared): |
2006 case X(0, MODconst | MODshared): | 2361 case X(0, MODconst | MODshared): |
2362 case X(0, MODwild): | |
2363 case X(0, MODwild | MODshared): | |
2007 // foo(U:U) T => T | 2364 // foo(U:U) T => T |
2008 // foo(U:U) const(T) => const(T) | 2365 // foo(U:U) const(T) => const(T) |
2009 // foo(U:U) immutable(T) => immutable(T) | 2366 // foo(U:U) immutable(T) => immutable(T) |
2010 // foo(U:U) shared(T) => shared(T) | 2367 // foo(U:U) shared(T) => shared(T) |
2011 // foo(U:U) const(shared(T)) => const(shared(T)) | 2368 // foo(U:U) const(shared(T)) => const(shared(T)) |
2369 // foo(U:U) wild(T) => wild(T) | |
2370 // foo(U:U) wild(shared(T)) => wild(shared(T)) | |
2012 if (!at) | 2371 if (!at) |
2013 { dedtypes[i] = tt; | 2372 { dedtypes[i] = tt; |
2014 goto Lexact; | 2373 goto Lexact; |
2015 } | 2374 } |
2016 break; | 2375 break; |
2017 | 2376 |
2018 case X(MODconst, MODconst): | 2377 case X(MODconst, MODconst): |
2019 case X(MODinvariant, MODinvariant): | 2378 case X(MODimmutable, MODimmutable): |
2020 case X(MODshared, MODshared): | 2379 case X(MODshared, MODshared): |
2021 case X(MODconst | MODshared, MODconst | MODshared): | 2380 case X(MODconst | MODshared, MODconst | MODshared): |
2381 case X(MODwild, MODwild): | |
2382 case X(MODwild | MODshared, MODwild | MODshared): | |
2383 case X(MODconst, MODwild): | |
2384 case X(MODconst, MODwild | MODshared): | |
2022 // foo(U:const(U)) const(T) => T | 2385 // foo(U:const(U)) const(T) => T |
2023 // foo(U:immutable(U)) immutable(T) => T | 2386 // foo(U:immutable(U)) immutable(T) => T |
2024 // foo(U:shared(U)) shared(T) => T | 2387 // foo(U:shared(U)) shared(T) => T |
2025 // foo(U:const(shared(U)) const(shared(T))=> T | 2388 // foo(U:const(shared(U)) const(shared(T))=> T |
2389 // foo(U:wild(U)) wild(T) => T | |
2390 // foo(U:wild(shared(U)) wild(shared(T)) => T | |
2391 // foo(U:const(U)) wild(shared(T)) => shared(T) | |
2026 tt = mutableOf().unSharedOf(); | 2392 tt = mutableOf().unSharedOf(); |
2027 if (!at) | 2393 if (!at) |
2028 { | 2394 { |
2029 dedtypes[i] = tt; | 2395 dedtypes[i] = tt; |
2030 goto Lexact; | 2396 goto Lexact; |
2033 | 2399 |
2034 case X(MODconst, 0): | 2400 case X(MODconst, 0): |
2035 case X(MODconst, MODimmutable): | 2401 case X(MODconst, MODimmutable): |
2036 case X(MODconst, MODconst | MODshared): | 2402 case X(MODconst, MODconst | MODshared): |
2037 case X(MODconst | MODshared, MODimmutable): | 2403 case X(MODconst | MODshared, MODimmutable): |
2404 case X(MODshared, MODwild | MODshared): | |
2038 // foo(U:const(U)) T => T | 2405 // foo(U:const(U)) T => T |
2039 // foo(U:const(U)) immutable(T) => T | 2406 // foo(U:const(U)) immutable(T) => T |
2040 // foo(U:const(U)) const(shared(T)) => shared(T) | 2407 // foo(U:const(U)) const(shared(T)) => shared(T) |
2041 // foo(U:const(shared(U)) immutable(T) => T | 2408 // foo(U:const(shared(U)) immutable(T) => T |
2409 // foo(U:shared(U)) wild(shared(T)) => wild(T) | |
2042 tt = mutableOf(); | 2410 tt = mutableOf(); |
2043 if (!at) | 2411 if (!at) |
2044 { dedtypes[i] = tt; | 2412 { dedtypes[i] = tt; |
2045 goto Lconst; | 2413 goto Lconst; |
2046 } | 2414 } |
2065 case X(MODshared, 0): | 2433 case X(MODshared, 0): |
2066 case X(MODshared, MODconst): | 2434 case X(MODshared, MODconst): |
2067 case X(MODshared, MODimmutable): | 2435 case X(MODshared, MODimmutable): |
2068 case X(MODconst | MODshared, 0): | 2436 case X(MODconst | MODshared, 0): |
2069 case X(MODconst | MODshared, MODconst): | 2437 case X(MODconst | MODshared, MODconst): |
2438 case X(MODimmutable, MODwild): | |
2439 case X(MODshared, MODwild): | |
2440 case X(MODconst | MODshared, MODwild): | |
2441 case X(MODwild, 0): | |
2442 case X(MODwild, MODconst): | |
2443 case X(MODwild, MODimmutable): | |
2444 case X(MODwild, MODshared): | |
2445 case X(MODwild, MODconst | MODshared): | |
2446 case X(MODwild | MODshared, 0): | |
2447 case X(MODwild | MODshared, MODconst): | |
2448 case X(MODwild | MODshared, MODimmutable): | |
2449 case X(MODwild | MODshared, MODshared): | |
2450 case X(MODwild | MODshared, MODconst | MODshared): | |
2451 case X(MODwild | MODshared, MODwild): | |
2452 case X(MODimmutable, MODwild | MODshared): | |
2453 case X(MODconst | MODshared, MODwild | MODshared): | |
2454 case X(MODwild, MODwild | MODshared): | |
2070 // foo(U:immutable(U)) T => nomatch | 2455 // foo(U:immutable(U)) T => nomatch |
2071 // foo(U:immutable(U)) const(T) => nomatch | 2456 // foo(U:immutable(U)) const(T) => nomatch |
2072 // foo(U:immutable(U)) shared(T) => nomatch | 2457 // foo(U:immutable(U)) shared(T) => nomatch |
2073 // foo(U:immutable(U)) const(shared(T)) => nomatch | 2458 // foo(U:immutable(U)) const(shared(T)) => nomatch |
2074 // foo(U:const(U)) shared(T) => nomatch | 2459 // foo(U:const(U)) shared(T) => nomatch |
2075 // foo(U:shared(U)) T => nomatch | 2460 // foo(U:shared(U)) T => nomatch |
2076 // foo(U:shared(U)) const(T) => nomatch | 2461 // foo(U:shared(U)) const(T) => nomatch |
2077 // foo(U:shared(U)) immutable(T) => nomatch | 2462 // foo(U:shared(U)) immutable(T) => nomatch |
2078 // foo(U:const(shared(U)) T => nomatch | 2463 // foo(U:const(shared(U)) T => nomatch |
2079 // foo(U:const(shared(U)) const(T) => nomatch | 2464 // foo(U:const(shared(U)) const(T) => nomatch |
2465 // foo(U:immutable(U)) wild(T) => nomatch | |
2466 // foo(U:shared(U)) wild(T) => nomatch | |
2467 // foo(U:const(shared(U)) wild(T) => nomatch | |
2468 // foo(U:wild(U)) T => nomatch | |
2469 // foo(U:wild(U)) const(T) => nomatch | |
2470 // foo(U:wild(U)) immutable(T) => nomatch | |
2471 // foo(U:wild(U)) shared(T) => nomatch | |
2472 // foo(U:wild(U)) const(shared(T)) => nomatch | |
2473 // foo(U:wild(shared(U)) T => nomatch | |
2474 // foo(U:wild(shared(U)) const(T) => nomatch | |
2475 // foo(U:wild(shared(U)) immutable(T) => nomatch | |
2476 // foo(U:wild(shared(U)) shared(T) => nomatch | |
2477 // foo(U:wild(shared(U)) const(shared(T)) => nomatch | |
2478 // foo(U:wild(shared(U)) wild(T) => nomatch | |
2479 // foo(U:immutable(U)) wild(shared(T)) => nomatch | |
2480 // foo(U:const(shared(U))) wild(shared(T)) => nomatch | |
2481 // foo(U:wild(U)) wild(shared(T)) => nomatch | |
2080 //if (!at) | 2482 //if (!at) |
2081 goto Lnomatch; | 2483 goto Lnomatch; |
2082 break; | 2484 break; |
2083 | 2485 |
2084 default: | 2486 default: |
2202 version (DMDV2) { | 2604 version (DMDV2) { |
2203 if (t.isShared()) // does both 'shared' and 'shared const' | 2605 if (t.isShared()) // does both 'shared' and 'shared const' |
2204 t.vtinfo = new TypeInfoSharedDeclaration(t); | 2606 t.vtinfo = new TypeInfoSharedDeclaration(t); |
2205 else if (t.isConst()) | 2607 else if (t.isConst()) |
2206 t.vtinfo = new TypeInfoConstDeclaration(t); | 2608 t.vtinfo = new TypeInfoConstDeclaration(t); |
2207 else if (t.isInvariant()) | 2609 else if (t.isImmutable()) |
2208 t.vtinfo = new TypeInfoInvariantDeclaration(t); | 2610 t.vtinfo = new TypeInfoInvariantDeclaration(t); |
2611 else if (t.isWild()) | |
2612 t.vtinfo = new TypeInfoWildDeclaration(t); | |
2613 | |
2209 else | 2614 else |
2210 t.vtinfo = t.getTypeInfoDeclaration(); | 2615 t.vtinfo = t.getTypeInfoDeclaration(); |
2211 } else { | 2616 } else { |
2212 t.vtinfo = t.getTypeInfoDeclaration(); | 2617 t.vtinfo = t.getTypeInfoDeclaration(); |
2213 } | 2618 } |
2259 Type reliesOnTident() | 2664 Type reliesOnTident() |
2260 { | 2665 { |
2261 return null; | 2666 return null; |
2262 } | 2667 } |
2263 | 2668 |
2669 /*************************************** | |
2670 * Return !=0 if the type or any of its subtypes is wild. | |
2671 */ | |
2672 | |
2673 int hasWild() | |
2674 { | |
2675 return mod & MOD.MODwild; | |
2676 } | |
2677 | |
2678 /*************************************** | |
2679 * Return MOD bits matching argument type (targ) to wild parameter type (this). | |
2680 */ | |
2681 | |
2682 uint wildMatch(Type targ) | |
2683 { | |
2684 return 0; | |
2685 } | |
2686 | |
2264 Expression toExpression() | 2687 Expression toExpression() |
2265 { | 2688 { |
2266 assert(false); | 2689 assert(false); |
2267 } | 2690 } |
2268 | 2691 |
2400 switch (mod) | 2823 switch (mod) |
2401 { | 2824 { |
2402 case MOD.MODundefined: | 2825 case MOD.MODundefined: |
2403 break; | 2826 break; |
2404 case MOD.MODconst: | 2827 case MOD.MODconst: |
2828 case MOD.MODwild: | |
2405 t |= mTY.mTYconst; | 2829 t |= mTY.mTYconst; |
2406 break; | 2830 break; |
2407 case MOD.MODinvariant: | 2831 case MOD.MODimmutable: |
2408 t |= mTY.mTYimmutable; | 2832 t |= mTY.mTYimmutable; |
2409 break; | 2833 break; |
2410 case MOD.MODshared: | 2834 case MOD.MODshared: |
2411 t |= mTY.mTYshared; | 2835 t |= mTY.mTYshared; |
2412 break; | 2836 break; |
2837 case MOD.MODshared | MOD.MODwild: | |
2413 case MOD.MODshared | MOD.MODconst: | 2838 case MOD.MODshared | MOD.MODconst: |
2414 t |= mTY.mTYshared | mTY.mTYconst; | 2839 t |= mTY.mTYshared | mTY.mTYconst; |
2415 break; | 2840 break; |
2416 default: | 2841 default: |
2417 assert(0); | 2842 assert(0); |