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