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