Mercurial > projects > ddmd
annotate dmd/TypeDelegate.d @ 154:14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
and enabled warnings
+ reduced warnings by adding appriopriate overrides
+ IfStatement.interpret()
+ ScopeStatement.interpret()
+ TypeSArray.constConv()
+ TypedefDeclaration.syntaxCopy()
* fixed a bug in StringExp
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 15:32:31 +0200 |
parents | af1bebfd96a4 |
children | af724d3510d7 |
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 { | |
41 super(TY.Tfunction, t); | |
42 ty = TY.Tdelegate; | |
43 } | |
44 | |
45 version (DumbClone) { | |
46 } else { | |
47 Type clone() | |
48 { | |
49 assert(false); | |
50 } | |
51 } | |
72 | 52 override Type syntaxCopy() |
0 | 53 { |
54 Type t = next.syntaxCopy(); | |
55 if (t == next) | |
56 t = this; | |
57 else | |
58 { | |
59 t = new TypeDelegate(t); | |
60 t.mod = mod; | |
61 } | |
62 return t; | |
63 } | |
64 | |
72 | 65 override Type semantic(Loc loc, Scope sc) |
0 | 66 { |
67 if (deco) // if semantic() already run | |
68 { | |
69 //printf("already done\n"); | |
70 return this; | |
71 } | |
72 | |
73 next = next.semantic(loc, sc); | |
74 return merge(); | |
75 } | |
76 | |
72 | 77 override ulong size(Loc loc) |
0 | 78 { |
79 return PTRSIZE * 2; | |
80 } | |
81 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
82 override MATCH implicitConvTo(Type to) |
96 | 83 { |
84 //writef("TypeDelegate::implicitConvTo(this=%p, to=%p)\n", this, to); | |
85 //writef("from: %s\n", toChars()); | |
86 //writef("to : %s\n", to.toChars()); | |
87 if (this == to) | |
88 return MATCHexact; | |
89 static if (false) // not allowing covariant conversions because it interferes with overriding | |
90 { | |
91 if (to.ty == Tdelegate && this.nextOf().covariant(to.nextOf()) == 1) | |
92 return MATCHconvert; | |
93 } | |
94 return MATCHnomatch; | |
95 } | |
96 | |
72 | 97 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 98 { |
99 if (mod != this.mod) | |
100 { | |
101 toCBuffer3(buf, hgs, mod); | |
102 return; | |
103 } | |
104 TypeFunction tf = cast(TypeFunction)next; | |
105 | |
106 tf.next.toCBuffer2(buf, hgs, MODundefined); | |
107 buf.writestring(" delegate"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
108 Parameter.argsToCBuffer(buf, hgs, tf.parameters, tf.varargs); |
0 | 109 } |
110 | |
72 | 111 override Expression defaultInit(Loc loc) |
0 | 112 { |
113 version (LOGDEFAULTINIT) { | |
114 printf("TypeDelegate.defaultInit() '%s'\n", toChars()); | |
115 } | |
135 | 116 return new NullExp(loc, this); |
0 | 117 } |
118 | |
72 | 119 override bool isZeroInit(Loc loc) |
0 | 120 { |
121 return true; | |
122 } | |
123 | |
72 | 124 override bool checkBoolean() |
0 | 125 { |
126 return true; | |
127 } | |
128 | |
72 | 129 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 130 { |
131 return new TypeInfoDelegateDeclaration(this); | |
132 } | |
133 | |
72 | 134 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 135 { |
136 version (LOGDOTEXP) { | |
137 printf("TypeDelegate.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
138 } | |
139 if (ident == Id.ptr) | |
140 { | |
141 e.type = tvoidptr; | |
142 return e; | |
143 } | |
144 else if (ident == Id.funcptr) | |
145 { | |
146 e = e.addressOf(sc); | |
147 e.type = tvoidptr; | |
148 e = new AddExp(e.loc, e, new IntegerExp(PTRSIZE)); | |
149 e.type = tvoidptr; | |
150 e = new PtrExp(e.loc, e); | |
151 e.type = next.pointerTo(); | |
152 return e; | |
153 } | |
154 else | |
155 { | |
156 e = Type.dotExp(sc, e, ident); | |
157 } | |
158 return e; | |
159 } | |
160 | |
72 | 161 override bool hasPointers() |
0 | 162 { |
163 return true; | |
164 } | |
165 | |
166 version (CPP_MANGLE) { | |
167 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
168 { | |
169 assert(false); | |
170 } | |
171 } | |
172 | |
72 | 173 override type* toCtype() |
0 | 174 { |
175 type* t; | |
176 | |
177 if (ctype) | |
178 return ctype; | |
179 | |
180 if (0 && global.params.symdebug) | |
181 { | |
182 /* A delegate consists of: | |
183 * _Delegate { void* frameptr; Function *funcptr; } | |
184 */ | |
185 | |
186 static Symbol* s; | |
187 | |
188 if (!s) | |
189 { | |
190 s = symbol_calloc("_Delegate"); | |
191 s.Sclass = SC.SCstruct; | |
192 s.Sstruct = struct_calloc(); | |
193 s.Sstruct.Sflags |= 0; /// huh? | |
194 s.Sstruct.Salignsize = alignsize(); | |
195 s.Sstruct.Sstructalign = cast(ubyte)global.structalign; | |
196 s.Sstruct.Sstructsize = cast(uint)size(Loc(0)); | |
197 slist_add(s); | |
198 | |
199 Symbol* s1 = symbol_name("frameptr", SC.SCmember, Type.tvoidptr.toCtype()); | |
200 list_append(&s.Sstruct.Sfldlst, s1); | |
201 | |
202 Symbol* s2 = symbol_name("funcptr", SC.SCmember, Type.tvoidptr.toCtype()); | |
203 s2.Smemoff = cast(uint)Type.tvoidptr.size(); | |
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 } |