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