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