Mercurial > projects > ddmd
annotate dmd/TypeDelegate.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 | fa9a71a9f5a8 |
children | b0d41ff5e0df |
rev | line source |
---|---|
0 | 1 module dmd.TypeDelegate; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
5 import dmd.TypeNext; | |
6 import dmd.MOD; | |
7 import dmd.OutBuffer; | |
8 import dmd.Id; | |
9 import dmd.AddExp; | |
10 import dmd.PtrExp; | |
11 import dmd.IntegerExp; | |
96 | 12 import dmd.MATCH; |
0 | 13 import dmd.NullExp; |
14 import dmd.TypeFunction; | |
15 import dmd.HdrGenState; | |
16 import dmd.Expression; | |
17 import dmd.Identifier; | |
18 import dmd.CppMangleState; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
19 import dmd.Parameter; |
0 | 20 import dmd.Loc; |
21 import dmd.Scope; | |
22 import dmd.TypeInfoDeclaration; | |
23 import dmd.TypeInfoDelegateDeclaration; | |
24 import dmd.TY; | |
25 import dmd.Global; | |
26 | |
27 import dmd.backend.TYPE; | |
28 import dmd.backend.Symbol; | |
29 import dmd.backend.Classsym; | |
30 import dmd.backend.TYM; | |
31 import dmd.backend.SC; | |
32 import dmd.backend.Util; | |
33 import dmd.backend.LIST; | |
34 | |
35 class TypeDelegate : TypeNext | |
36 { | |
37 // .next is a TypeFunction | |
38 | |
39 this(Type t) | |
40 { | |
178 | 41 register(); |
0 | 42 super(TY.Tfunction, t); |
43 ty = TY.Tdelegate; | |
44 } | |
45 | |
72 | 46 override Type syntaxCopy() |
0 | 47 { |
48 Type t = next.syntaxCopy(); | |
49 if (t == next) | |
50 t = this; | |
51 else | |
52 { | |
53 t = new TypeDelegate(t); | |
54 t.mod = mod; | |
55 } | |
56 return t; | |
57 } | |
58 | |
72 | 59 override Type semantic(Loc loc, Scope sc) |
0 | 60 { |
61 if (deco) // if semantic() already run | |
62 { | |
63 //printf("already done\n"); | |
64 return this; | |
65 } | |
66 | |
67 next = next.semantic(loc, sc); | |
68 return merge(); | |
69 } | |
70 | |
72 | 71 override ulong size(Loc loc) |
0 | 72 { |
73 return PTRSIZE * 2; | |
74 } | |
75 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
76 override MATCH implicitConvTo(Type to) |
96 | 77 { |
78 //writef("TypeDelegate::implicitConvTo(this=%p, to=%p)\n", this, to); | |
79 //writef("from: %s\n", toChars()); | |
80 //writef("to : %s\n", to.toChars()); | |
81 if (this == to) | |
82 return MATCHexact; | |
83 static if (false) // not allowing covariant conversions because it interferes with overriding | |
84 { | |
85 if (to.ty == Tdelegate && this.nextOf().covariant(to.nextOf()) == 1) | |
86 return MATCHconvert; | |
87 } | |
88 return MATCHnomatch; | |
89 } | |
90 | |
72 | 91 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 92 { |
93 if (mod != this.mod) | |
94 { | |
95 toCBuffer3(buf, hgs, mod); | |
96 return; | |
97 } | |
98 TypeFunction tf = cast(TypeFunction)next; | |
99 | |
100 tf.next.toCBuffer2(buf, hgs, MODundefined); | |
101 buf.writestring(" delegate"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
102 Parameter.argsToCBuffer(buf, hgs, tf.parameters, tf.varargs); |
0 | 103 } |
104 | |
72 | 105 override Expression defaultInit(Loc loc) |
0 | 106 { |
107 version (LOGDEFAULTINIT) { | |
108 printf("TypeDelegate.defaultInit() '%s'\n", toChars()); | |
109 } | |
135 | 110 return new NullExp(loc, this); |
0 | 111 } |
112 | |
72 | 113 override bool isZeroInit(Loc loc) |
0 | 114 { |
115 return true; | |
116 } | |
117 | |
72 | 118 override bool checkBoolean() |
0 | 119 { |
120 return true; | |
121 } | |
122 | |
72 | 123 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 124 { |
125 return new TypeInfoDelegateDeclaration(this); | |
126 } | |
127 | |
72 | 128 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 129 { |
130 version (LOGDOTEXP) { | |
131 printf("TypeDelegate.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
132 } | |
176 | 133 auto tvoidptr = global.tvoidptr; |
0 | 134 if (ident == Id.ptr) |
135 { | |
136 e.type = tvoidptr; | |
137 return e; | |
138 } | |
139 else if (ident == Id.funcptr) | |
140 { | |
141 e = e.addressOf(sc); | |
142 e.type = tvoidptr; | |
143 e = new AddExp(e.loc, e, new IntegerExp(PTRSIZE)); | |
144 e.type = tvoidptr; | |
145 e = new PtrExp(e.loc, e); | |
146 e.type = next.pointerTo(); | |
147 return e; | |
148 } | |
149 else | |
150 { | |
151 e = Type.dotExp(sc, e, ident); | |
152 } | |
153 return e; | |
154 } | |
155 | |
72 | 156 override bool hasPointers() |
0 | 157 { |
158 return true; | |
159 } | |
160 | |
161 version (CPP_MANGLE) { | |
162 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
163 { | |
164 assert(false); | |
165 } | |
166 } | |
167 | |
72 | 168 override type* toCtype() |
0 | 169 { |
170 type* t; | |
171 | |
172 if (ctype) | |
173 return ctype; | |
174 | |
175 if (0 && global.params.symdebug) | |
176 { | |
177 /* A delegate consists of: | |
178 * _Delegate { void* frameptr; Function *funcptr; } | |
179 */ | |
180 | |
176 | 181 auto s = global.Delegate_s; |
0 | 182 if (!s) |
183 { | |
176 | 184 global.Delegate_s = s = symbol_calloc("_Delegate"); |
0 | 185 s.Sclass = SC.SCstruct; |
186 s.Sstruct = struct_calloc(); | |
187 s.Sstruct.Sflags |= 0; /// huh? | |
188 s.Sstruct.Salignsize = alignsize(); | |
189 s.Sstruct.Sstructalign = cast(ubyte)global.structalign; | |
190 s.Sstruct.Sstructsize = cast(uint)size(Loc(0)); | |
191 slist_add(s); | |
192 | |
176 | 193 auto tvoidptr = global.tvoidptr; |
194 | |
195 Symbol* s1 = symbol_name("frameptr", SC.SCmember, tvoidptr.toCtype()); | |
0 | 196 list_append(&s.Sstruct.Sfldlst, s1); |
197 | |
176 | 198 Symbol* s2 = symbol_name("funcptr", SC.SCmember, tvoidptr.toCtype()); |
199 s2.Smemoff = cast(uint)tvoidptr.size(); | |
0 | 200 list_append(&s.Sstruct.Sfldlst, s2); |
201 } | |
202 | |
203 t = type_alloc(TYM.TYstruct); | |
204 t.Ttag = cast(Classsym*)s; // structure tag name | |
205 t.Tcount++; | |
206 s.Stype = t; | |
207 } | |
208 else | |
209 { | |
210 if (global.params.symdebug == 1) | |
211 { | |
212 // Generate D symbolic debug info, rather than C | |
213 t = type_allocn(TYM.TYdelegate, next.toCtype()); | |
214 } | |
215 else | |
216 t = type_fake(TYM.TYdelegate); | |
217 } | |
218 | |
219 t.Tcount++; | |
220 ctype = t; | |
221 return t; | |
222 } | |
72 | 223 } |