Mercurial > projects > ddmd
annotate dmd/TypeNext.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.TypeNext; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
96 | 5 import dmd.TypeAArray; |
0 | 6 import dmd.TY; |
7 import dmd.OutBuffer; | |
8 import dmd.Loc; | |
9 import dmd.Scope; | |
10 import dmd.MATCH; | |
11 import dmd.MOD; | |
12 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
13 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
14 |
0 | 15 class TypeNext : Type |
16 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
17 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
18 |
0 | 19 Type next; |
20 | |
21 this(TY ty, Type next) | |
22 { | |
178 | 23 register(); |
0 | 24 super(ty); |
25 this.next = next; | |
26 } | |
27 | |
72 | 28 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 29 { |
30 super.toDecoBuffer(buf, flag); | |
31 assert(next !is this); | |
32 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this.ty, next, next.ty); | |
33 next.toDecoBuffer(buf, (flag & 0x100) ? 0 : mod); | |
34 } | |
35 | |
72 | 36 override void checkDeprecated(Loc loc, Scope sc) |
0 | 37 { |
38 Type.checkDeprecated(loc, sc); | |
39 if (next) // next can be null if TypeFunction and auto return type | |
40 next.checkDeprecated(loc, sc); | |
41 } | |
42 | |
72 | 43 override Type reliesOnTident() |
0 | 44 { |
45 return next.reliesOnTident(); | |
46 } | |
47 | |
135 | 48 override int hasWild() |
49 { | |
50 return mod == MOD.MODwild || next.hasWild(); | |
51 } | |
52 | |
53 /*************************************** | |
54 * Return MOD bits matching argument type (targ) to wild parameter type (this). | |
55 */ | |
56 | |
57 override uint wildMatch(Type targ) | |
58 { | |
59 uint mod; | |
60 | |
61 Type tb = targ.nextOf(); | |
62 if (!tb) | |
63 return 0; | |
64 tb = tb.toBasetype(); | |
65 if (tb.isMutable()) | |
66 mod = MOD.MODmutable; | |
67 else if (tb.isConst() || tb.isWild()) | |
68 return MOD.MODconst; | |
69 else if (tb.isImmutable()) | |
70 mod = MOD.MODimmutable; | |
71 else | |
72 assert(0); | |
73 mod |= next.wildMatch(tb); | |
74 return mod; | |
75 } | |
76 | |
72 | 77 override Type nextOf() |
0 | 78 { |
79 return next; | |
80 } | |
81 | |
72 | 82 override Type makeConst() |
0 | 83 { |
84 //printf("TypeNext::makeConst() %p, %s\n", this, toChars()); | |
85 if (cto) | |
86 { | |
87 assert(cto.mod == MOD.MODconst); | |
88 return cto; | |
89 } | |
90 | |
91 TypeNext t = cast(TypeNext)super.makeConst(); | |
92 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
93 (next.deco || next.ty == TY.Tfunction) && | |
135 | 94 !next.isImmutable() && !next.isConst()) |
0 | 95 { |
96 if (next.isShared()) | |
97 t.next = next.sharedConstOf(); | |
98 else | |
99 t.next = next.constOf(); | |
100 } | |
96 | 101 if (ty == Taarray) |
102 { | |
103 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
104 } | |
105 //writef("TypeNext::makeConst() returns %p, %s\n", t, t.toChars()); | |
0 | 106 return t; |
107 } | |
108 | |
72 | 109 override Type makeInvariant() |
0 | 110 { |
111 //printf("TypeNext::makeInvariant() %s\n", toChars()); | |
112 if (ito) | |
113 { | |
135 | 114 assert(ito.isImmutable()); |
0 | 115 return ito; |
116 } | |
117 TypeNext t = cast(TypeNext)Type.makeInvariant(); | |
135 | 118 if (ty != TY.Tfunction && ty != TY.Tdelegate && (next.deco || next.ty == TY.Tfunction) && !next.isImmutable()) |
0 | 119 { |
120 t.next = next.invariantOf(); | |
121 } | |
96 | 122 if (ty == Taarray) |
123 { | |
124 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
125 } | |
0 | 126 return t; |
127 } | |
128 | |
72 | 129 override Type makeShared() |
0 | 130 { |
131 //printf("TypeNext::makeShared() %s\n", toChars()); | |
132 if (sto) | |
133 { | |
134 assert(sto.mod == MODshared); | |
135 return sto; | |
136 } | |
137 TypeNext t = cast(TypeNext)Type.makeShared(); | |
138 if (ty != Tfunction && ty != Tdelegate && | |
139 (next.deco || next.ty == Tfunction) && | |
135 | 140 !next.isImmutable() && !next.isShared()) |
0 | 141 { |
135 | 142 if (next.isConst() || next.isWild()) |
0 | 143 t.next = next.sharedConstOf(); |
144 else | |
145 t.next = next.sharedOf(); | |
146 } | |
96 | 147 if (ty == Taarray) |
148 { | |
149 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
150 } | |
151 //writef("TypeNext::makeShared() returns %p, %s\n", t, t.toChars()); | |
0 | 152 return t; |
153 } | |
154 | |
96 | 155 override Type makeSharedConst() |
0 | 156 { |
96 | 157 //printf("TypeNext::makeSharedConst() %s\n", toChars()); |
158 if (scto) | |
159 { | |
160 assert(scto.mod == (MODshared | MODconst)); | |
161 return scto; | |
162 } | |
163 TypeNext t = cast(TypeNext) Type.makeSharedConst(); | |
164 if (ty != Tfunction && ty != Tdelegate && | |
165 (next.deco || next.ty == Tfunction) && | |
135 | 166 !next.isImmutable() && !next.isSharedConst()) |
96 | 167 { |
168 t.next = next.sharedConstOf(); | |
169 } | |
170 if (ty == Taarray) | |
171 { | |
172 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
173 } | |
174 // writef("TypeNext::makeSharedConst() returns %p, %s\n", t, t.toChars()); | |
175 return t; | |
0 | 176 } |
177 | |
135 | 178 override Type makeWild() |
179 { | |
180 //printf("TypeNext::makeWild() %s\n", toChars()); | |
181 if (wto) | |
182 { | |
183 assert(wto.mod == MODwild); | |
184 return wto; | |
185 } | |
186 auto t = cast(TypeNext)Type.makeWild(); | |
187 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
188 (next.deco || next.ty == TY.Tfunction) && | |
189 !next.isImmutable() && !next.isConst() && !next.isWild()) | |
190 { | |
191 if (next.isShared()) | |
192 t.next = next.sharedWildOf(); | |
193 else | |
194 t.next = next.wildOf(); | |
195 } | |
196 if (ty == TY.Taarray) | |
197 { | |
198 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
199 } | |
200 //printf("TypeNext::makeWild() returns %p, %s\n", t, t->toChars()); | |
201 return t; | |
202 } | |
203 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
204 override Type makeSharedWild() |
135 | 205 { |
206 //printf("TypeNext::makeSharedWild() %s\n", toChars()); | |
207 if (swto) | |
208 { | |
209 assert(swto.isSharedWild()); | |
210 return swto; | |
211 } | |
212 auto t = cast(TypeNext)Type.makeSharedWild(); | |
213 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
214 (next.deco || next.ty == TY.Tfunction) && | |
215 !next.isImmutable() && !next.isSharedConst()) | |
216 { | |
217 t.next = next.sharedWildOf(); | |
218 } | |
219 if (ty == Taarray) | |
220 { | |
221 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
222 } | |
223 //printf("TypeNext::makeSharedWild() returns %p, %s\n", t, t->toChars()); | |
224 return t; | |
225 } | |
226 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
227 override Type makeMutable() |
135 | 228 { |
229 //printf("TypeNext::makeMutable() %p, %s\n", this, toChars()); | |
230 auto t = cast(TypeNext)Type.makeMutable(); | |
231 if (ty != TY.Tfunction && ty != TY.Tdelegate && | |
232 (next.deco || next.ty == TY.Tfunction) && | |
233 next.isWild()) | |
234 { | |
235 t.next = next.mutableOf(); | |
236 } | |
237 if (ty == Taarray) | |
238 { | |
239 (cast(TypeAArray)t).impl = null; // lazily recompute it | |
240 } | |
241 //printf("TypeNext::makeMutable() returns %p, %s\n", t, t->toChars()); | |
242 return t; | |
243 } | |
244 | |
96 | 245 override MATCH constConv(Type to) |
0 | 246 { |
56 | 247 MATCH m = Type.constConv(to); |
248 | |
249 if (m == MATCHconst && next.constConv((cast(TypeNext)to).next) == MATCHnomatch) | |
250 m = MATCHnomatch; | |
251 return m; | |
0 | 252 } |
253 | |
96 | 254 void transitive() |
0 | 255 { |
256 /* Invoke transitivity of type attributes | |
257 */ | |
258 next = next.addMod(mod); | |
259 } | |
72 | 260 } |