Mercurial > projects > ddmd
comparison dmd/TypeNext.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | e28b18c23469 |
children | 14feb7ae01a6 |
comparison
equal
deleted
inserted
replaced
134:4251f96733f4 | 135:af1bebfd96a4 |
---|---|
51 override Type reliesOnTident() | 51 override Type reliesOnTident() |
52 { | 52 { |
53 return next.reliesOnTident(); | 53 return next.reliesOnTident(); |
54 } | 54 } |
55 | 55 |
56 override int hasWild() | |
57 { | |
58 return mod == MOD.MODwild || next.hasWild(); | |
59 } | |
60 | |
61 /*************************************** | |
62 * Return MOD bits matching argument type (targ) to wild parameter type (this). | |
63 */ | |
64 | |
65 override uint wildMatch(Type targ) | |
66 { | |
67 uint mod; | |
68 | |
69 Type tb = targ.nextOf(); | |
70 if (!tb) | |
71 return 0; | |
72 tb = tb.toBasetype(); | |
73 if (tb.isMutable()) | |
74 mod = MOD.MODmutable; | |
75 else if (tb.isConst() || tb.isWild()) | |
76 return MOD.MODconst; | |
77 else if (tb.isImmutable()) | |
78 mod = MOD.MODimmutable; | |
79 else | |
80 assert(0); | |
81 mod |= next.wildMatch(tb); | |
82 return mod; | |
83 } | |
84 | |
56 override Type nextOf() | 85 override Type nextOf() |
57 { | 86 { |
58 return next; | 87 return next; |
59 } | 88 } |
60 | 89 |
68 } | 97 } |
69 | 98 |
70 TypeNext t = cast(TypeNext)super.makeConst(); | 99 TypeNext t = cast(TypeNext)super.makeConst(); |
71 if (ty != TY.Tfunction && ty != TY.Tdelegate && | 100 if (ty != TY.Tfunction && ty != TY.Tdelegate && |
72 (next.deco || next.ty == TY.Tfunction) && | 101 (next.deco || next.ty == TY.Tfunction) && |
73 !next.isInvariant() && !next.isConst()) | 102 !next.isImmutable() && !next.isConst()) |
74 { | 103 { |
75 if (next.isShared()) | 104 if (next.isShared()) |
76 t.next = next.sharedConstOf(); | 105 t.next = next.sharedConstOf(); |
77 else | 106 else |
78 t.next = next.constOf(); | 107 t.next = next.constOf(); |
88 override Type makeInvariant() | 117 override Type makeInvariant() |
89 { | 118 { |
90 //printf("TypeNext::makeInvariant() %s\n", toChars()); | 119 //printf("TypeNext::makeInvariant() %s\n", toChars()); |
91 if (ito) | 120 if (ito) |
92 { | 121 { |
93 assert(ito.isInvariant()); | 122 assert(ito.isImmutable()); |
94 return ito; | 123 return ito; |
95 } | 124 } |
96 TypeNext t = cast(TypeNext)Type.makeInvariant(); | 125 TypeNext t = cast(TypeNext)Type.makeInvariant(); |
97 if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isInvariant()) | 126 if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isImmutable()) |
98 { | 127 { |
99 t.next = next.invariantOf(); | 128 t.next = next.invariantOf(); |
100 } | 129 } |
101 if (ty == Taarray) | 130 if (ty == Taarray) |
102 { | 131 { |
114 return sto; | 143 return sto; |
115 } | 144 } |
116 TypeNext t = cast(TypeNext)Type.makeShared(); | 145 TypeNext t = cast(TypeNext)Type.makeShared(); |
117 if (ty != Tfunction && ty != Tdelegate && | 146 if (ty != Tfunction && ty != Tdelegate && |
118 (next.deco || next.ty == Tfunction) && | 147 (next.deco || next.ty == Tfunction) && |
119 !next.isInvariant() && !next.isShared()) | 148 !next.isImmutable() && !next.isShared()) |
120 { | 149 { |
121 if (next.isConst()) | 150 if (next.isConst() || next.isWild()) |
122 t.next = next.sharedConstOf(); | 151 t.next = next.sharedConstOf(); |
123 else | 152 else |
124 t.next = next.sharedOf(); | 153 t.next = next.sharedOf(); |
125 } | 154 } |
126 if (ty == Taarray) | 155 if (ty == Taarray) |
140 return scto; | 169 return scto; |
141 } | 170 } |
142 TypeNext t = cast(TypeNext) Type.makeSharedConst(); | 171 TypeNext t = cast(TypeNext) Type.makeSharedConst(); |
143 if (ty != Tfunction && ty != Tdelegate && | 172 if (ty != Tfunction && ty != Tdelegate && |
144 (next.deco || next.ty == Tfunction) && | 173 (next.deco || next.ty == Tfunction) && |
145 !next.isInvariant() && !next.isSharedConst()) | 174 !next.isImmutable() && !next.isSharedConst()) |
146 { | 175 { |
147 t.next = next.sharedConstOf(); | 176 t.next = next.sharedConstOf(); |
148 } | 177 } |
149 if (ty == Taarray) | 178 if (ty == Taarray) |
150 { | 179 { |
152 } | 181 } |
153 // writef("TypeNext::makeSharedConst() returns %p, %s\n", t, t.toChars()); | 182 // writef("TypeNext::makeSharedConst() returns %p, %s\n", t, t.toChars()); |
154 return t; | 183 return t; |
155 } | 184 } |
156 | 185 |
186 override Type makeWild() | |
187 { | |
188 //printf("TypeNext::makeWild() %s\n", toChars()); | |
189 if (wto) | |
190 { | |
191 assert(wto.mod == MODwild); | |
192 return wto; | |
193 } | |
194 auto t = cast(TypeNext)Type.makeWild(); | |
195 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
196 (next.deco || next.ty == TY.Tfunction) && | |
197 !next.isImmutable() && !next.isConst() && !next.isWild()) | |
198 { | |
199 if (next.isShared()) | |
200 t.next = next.sharedWildOf(); | |
201 else | |
202 t.next = next.wildOf(); | |
203 } | |
204 if (ty == TY.Taarray) | |
205 { | |
206 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
207 } | |
208 //printf("TypeNext::makeWild() returns %p, %s\n", t, t->toChars()); | |
209 return t; | |
210 } | |
211 | |
212 Type makeSharedWild() | |
213 { | |
214 //printf("TypeNext::makeSharedWild() %s\n", toChars()); | |
215 if (swto) | |
216 { | |
217 assert(swto.isSharedWild()); | |
218 return swto; | |
219 } | |
220 auto t = cast(TypeNext)Type.makeSharedWild(); | |
221 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
222 (next.deco || next.ty == TY.Tfunction) && | |
223 !next.isImmutable() && !next.isSharedConst()) | |
224 { | |
225 t.next = next.sharedWildOf(); | |
226 } | |
227 if (ty == Taarray) | |
228 { | |
229 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
230 } | |
231 //printf("TypeNext::makeSharedWild() returns %p, %s\n", t, t->toChars()); | |
232 return t; | |
233 } | |
234 | |
235 Type makeMutable() | |
236 { | |
237 //printf("TypeNext::makeMutable() %p, %s\n", this, toChars()); | |
238 auto t = cast(TypeNext)Type.makeMutable(); | |
239 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
240 (next.deco || next.ty == TY.Tfunction) && | |
241 next.isWild()) | |
242 { | |
243 t.next = next.mutableOf(); | |
244 } | |
245 if (ty == Taarray) | |
246 { | |
247 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
248 } | |
249 //printf("TypeNext::makeMutable() returns %p, %s\n", t, t->toChars()); | |
250 return t; | |
251 } | |
252 | |
157 override MATCH constConv(Type to) | 253 override MATCH constConv(Type to) |
158 { | 254 { |
159 MATCH m = Type.constConv(to); | 255 MATCH m = Type.constConv(to); |
160 | 256 |
161 if (m == MATCHconst && next.constConv((cast(TypeNext)to).next) == MATCHnomatch) | 257 if (m == MATCHconst && next.constConv((cast(TypeNext)to).next) == MATCHnomatch) |