Mercurial > projects > ddmd
annotate dmd/TypeFunction.d @ 148:fe2e1b93e88f
phobos compiles now:
* fixed upgrade mistake in interpret.Util
+ implemented missing methods in RealExp,VarExp
author | Trass3r |
---|---|
date | Wed, 15 Sep 2010 03:58:55 +0200 |
parents | 95b3ed3cddd5 |
children | b7b61140701d |
rev | line source |
---|---|
0 | 1 module dmd.TypeFunction; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TypeNext; |
5 import dmd.TypeSArray; | |
6 import dmd.TypeArray; | |
123 | 7 import dmd.TemplateTupleParameter; |
0 | 8 import dmd.ArrayTypes; |
9 import dmd.LINK; | |
10 import dmd.StructDeclaration; | |
11 import dmd.TypeStruct; | |
12 import dmd.Global; | |
13 import dmd.STC; | |
14 import dmd.MOD; | |
73 | 15 import dmd.PROT; |
123 | 16 import dmd.TypeIdentifier; |
17 import dmd.TemplateParameter; | |
129 | 18 import dmd.TypeInfoFunctionDeclaration; |
123 | 19 import dmd.Tuple; |
0 | 20 import dmd.Type; |
21 import dmd.Loc; | |
22 import dmd.Scope; | |
23 import dmd.Identifier; | |
24 import dmd.OutBuffer; | |
25 import dmd.HdrGenState; | |
26 import dmd.CppMangleState; | |
27 import dmd.TypeInfoDeclaration; | |
28 import dmd.MATCH; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
29 import dmd.Parameter; |
0 | 30 import dmd.Expression; |
31 import dmd.RET; | |
32 import dmd.TY; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
33 import dmd.TRUST; |
0 | 34 import dmd.Util; |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
35 import dmd.FuncDeclaration; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
36 import dmd.Dsymbol; |
135 | 37 import dmd.TypeTuple; |
123 | 38 import dmd.TemplateInstance : isTuple; |
0 | 39 |
40 import dmd.backend.TYPE; | |
41 import dmd.backend.PARAM; | |
42 import dmd.backend.Util; | |
43 import dmd.backend.TYM; | |
44 import dmd.backend.TF; | |
45 import dmd.backend.mTY; | |
46 | |
47 import core.stdc.stdlib; | |
48 import core.stdc.string; | |
49 | |
129 | 50 import std.stdio; |
51 | |
0 | 52 class TypeFunction : TypeNext |
53 { | |
54 // .next is the return type | |
55 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
56 Parameters parameters; // function parameters |
0 | 57 int varargs; // 1: T t, ...) style for variable number of arguments |
58 // 2: T t ...) style for variable number of arguments | |
59 bool isnothrow; // true: nothrow | |
60 bool ispure; // true: pure | |
61 bool isproperty; // can be called without parentheses | |
62 bool isref; // true: returns a reference | |
63 LINK linkage; // calling convention | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
64 TRUST trust; // level of trust |
135 | 65 Expressions fargs; // function arguments |
0 | 66 |
67 int inuse; | |
68 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
69 this(Parameters parameters, Type treturn, int varargs, LINK linkage) |
0 | 70 { |
71 super(TY.Tfunction, treturn); | |
72 | |
73 //if (!treturn) *(char*)0=0; | |
74 // assert(treturn); | |
75 assert(0 <= varargs && varargs <= 2); | |
76 this.parameters = parameters; | |
77 this.varargs = varargs; | |
78 this.linkage = linkage; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
79 this.trust = TRUSTdefault; |
0 | 80 } |
81 | |
72 | 82 override Type syntaxCopy() |
0 | 83 { |
84 Type treturn = next ? next.syntaxCopy() : null; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
85 auto params = Parameter.arraySyntaxCopy(parameters); |
0 | 86 TypeFunction t = new TypeFunction(params, treturn, varargs, linkage); |
87 t.mod = mod; | |
88 t.isnothrow = isnothrow; | |
89 t.ispure = ispure; | |
90 t.isproperty = isproperty; | |
91 t.isref = isref; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
92 t.trust = trust; |
135 | 93 t.fargs = fargs; |
0 | 94 |
95 return t; | |
96 } | |
97 | |
98 version (DumbClone) { | |
99 } else { | |
100 final TypeFunction cloneTo(TypeFunction t) | |
101 { | |
102 super.cloneTo(t); | |
103 | |
104 // these 3 should be set by ctor | |
105 assert(t.parameters is null); | |
106 assert(t.varargs == varargs); | |
107 assert(t.linkage == linkage); | |
108 | |
109 t.isnothrow = isnothrow; | |
110 t.ispure = ispure; | |
111 t.isproperty = isproperty; | |
112 t.isref = isref; | |
113 t.inuse = inuse; | |
114 | |
115 if (parameters) | |
116 { | |
117 t.parameters = parameters.copy(); | |
129 | 118 foreach (arg; parameters) |
0 | 119 { |
120 Argument cpy = arg.clone(); | |
129 | 121 t.parameters[i] = cpy; |
0 | 122 } |
123 } | |
124 | |
125 return t; | |
126 } | |
127 | |
128 TypeFunction clone() | |
129 { | |
129 | 130 assert(this.classinfo is TypeFunction.classinfo); |
0 | 131 return cloneTo(new TypeFunction(null, next, varargs, linkage)); |
132 } | |
133 } | |
72 | 134 override Type semantic(Loc loc, Scope sc) |
0 | 135 { |
136 if (deco) // if semantic() already run | |
137 { | |
138 //printf("already done\n"); | |
139 return this; | |
140 } | |
141 //printf("TypeFunction.semantic() this = %p\n", this); | |
135 | 142 //printf("TypeFunction::semantic() %s, sc->stc = %llx, fargs = %p\n", toChars(), sc->stc, fargs); |
0 | 143 |
144 /* Copy in order to not mess up original. | |
145 * This can produce redundant copies if inferring return type, | |
146 * as semantic() will get called again on this. | |
147 */ | |
148 | |
129 | 149 TypeFunction tf = cloneThis(this); |
0 | 150 |
151 if (sc.stc & STC.STCpure) | |
152 tf.ispure = true; | |
153 if (sc.stc & STC.STCnothrow) | |
154 tf.isnothrow = true; | |
155 if (sc.stc & STC.STCref) | |
156 tf.isref = true; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
157 if (sc.stc & STCsafe) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
158 tf.trust = TRUST.TRUSTsafe; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
159 if (sc.stc & STCtrusted) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
160 tf.trust = TRUST.TRUSTtrusted; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
161 if (sc.stc & STCproperty) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
162 tf.isproperty = true; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
163 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
164 tf.linkage = sc.linkage; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
165 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
166 /* If the parent is @safe, then this function defaults to safe |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
167 * too. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
168 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
169 if (tf.trust == TRUST.TRUSTdefault) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
170 for (Dsymbol p = sc.func; p; p = p.toParent2()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
171 { FuncDeclaration fd = p.isFuncDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
172 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
173 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
174 if (fd.isSafe()) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
175 tf.trust = TRUST.TRUSTsafe; // default to @safe |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
176 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
177 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
178 } |
0 | 179 |
135 | 180 bool wildreturn = false; |
0 | 181 if (tf.next) |
182 { | |
183 tf.next = tf.next.semantic(loc,sc); | |
96 | 184 version(SARRAYVALUE) {} else |
185 { | |
0 | 186 if (tf.next.toBasetype().ty == TY.Tsarray) |
129 | 187 { |
188 error(loc, "functions cannot return static array %s", tf.next.toChars()); | |
0 | 189 tf.next = Type.terror; |
190 } | |
96 | 191 } |
0 | 192 if (tf.next.toBasetype().ty == TY.Tfunction) |
129 | 193 { |
194 error(loc, "functions cannot return a function"); | |
0 | 195 tf.next = Type.terror; |
196 } | |
197 if (tf.next.toBasetype().ty == TY.Ttuple) | |
129 | 198 { |
199 error(loc, "functions cannot return a tuple"); | |
0 | 200 tf.next = Type.terror; |
201 } | |
202 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) | |
129 | 203 error(loc, "functions cannot return scope %s", tf.next.toChars()); |
135 | 204 if (tf.next.toBasetype().ty == TY.Tvoid) |
205 tf.isref = false; // rewrite "ref void" as just "void" | |
206 if (tf.next.isWild()) | |
207 wildreturn = true; | |
208 } | |
0 | 209 |
135 | 210 bool wildparams = false; |
211 bool wildsubparams = false; | |
0 | 212 if (tf.parameters) |
73 | 213 { |
214 /* Create a scope for evaluating the default arguments for the parameters | |
215 */ | |
216 Scope argsc = sc.push(); | |
217 argsc.stc = STCundefined; // don't inherit storage class | |
218 argsc.protection = PROT.PROTpublic; | |
219 | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
220 size_t dim = Parameter.dim(tf.parameters); |
0 | 221 |
222 for (size_t i = 0; i < dim; i++) | |
135 | 223 { auto fparam = Parameter.getNth(tf.parameters, i); |
0 | 224 |
225 tf.inuse++; | |
135 | 226 fparam.type = fparam.type.semantic(loc, argsc); |
0 | 227 if (tf.inuse == 1) tf.inuse--; |
228 | |
135 | 229 fparam.type = fparam.type.addStorageClass(fparam.storageClass); |
0 | 230 |
135 | 231 if (fparam.storageClass & (STC.STCauto | STC.STCalias | STC.STCstatic)) |
0 | 232 { |
135 | 233 if (!fparam.type) |
0 | 234 continue; |
235 } | |
236 | |
135 | 237 Type t = fparam.type.toBasetype(); |
0 | 238 |
135 | 239 if (fparam.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) |
0 | 240 { |
96 | 241 //if (t.ty == TY.Tsarray) |
242 //error(loc, "cannot have out or ref parameter of type %s", t.toChars()); | |
135 | 243 if (fparam.storageClass & STC.STCout && fparam.type.mod & (STCconst | STCimmutable)) |
96 | 244 error(loc, "cannot have const or immutabl out parameter of type %s", t.toChars()); |
0 | 245 } |
135 | 246 if (!(fparam.storageClass & STC.STClazy) && t.ty == TY.Tvoid) |
247 error(loc, "cannot have parameter of type %s", fparam.type.toChars()); | |
0 | 248 |
135 | 249 if (t.isWild()) |
250 { | |
251 wildparams = true; | |
252 if (tf.next && !wildreturn) | |
253 error(loc, "inout on parameter means inout must be on return type as well (if from D1 code, replace with 'ref')"); | |
254 } | |
255 else if (!wildsubparams && t.hasWild()) | |
256 wildsubparams = true; | |
0 | 257 |
135 | 258 if (fparam.defaultArg) |
259 { | |
260 fparam.defaultArg = fparam.defaultArg.semantic(argsc); | |
261 fparam.defaultArg = resolveProperties(argsc, fparam.defaultArg); | |
262 fparam.defaultArg = fparam.defaultArg.implicitCastTo(argsc, fparam.type); | |
263 } | |
264 | |
265 /* If fparam turns out to be a tuple, the number of parameters may | |
0 | 266 * change. |
267 */ | |
268 if (t.ty == TY.Ttuple) | |
135 | 269 { |
270 // Propagate storage class from tuple parameters to their element-parameters. | |
271 auto tt = cast(TypeTuple)t; | |
272 if (tt.arguments) | |
273 { | |
274 auto tdim = tt.arguments.dim; | |
275 foreach (narg; tt.arguments) | |
276 { | |
277 narg.storageClass = fparam.storageClass; | |
278 } | |
279 } | |
280 | |
281 /* Reset number of parameters, and back up one to do this fparam again, | |
282 * now that it is the first element of a tuple | |
283 */ | |
284 dim = Parameter.dim(tf.parameters); | |
0 | 285 i--; |
135 | 286 continue; |
0 | 287 } |
135 | 288 |
289 /* Resolve "auto ref" storage class to be either ref or value, | |
290 * based on the argument matching the parameter | |
291 */ | |
292 if (fparam.storageClass & STC.STCauto) | |
293 { | |
294 if (fargs && i < fargs.dim) | |
295 { | |
296 auto farg = fargs[i]; | |
297 if (farg.isLvalue()) | |
298 {} // ref parameter | |
299 else | |
300 fparam.storageClass &= ~STC.STCref; // value parameter | |
301 } | |
302 else | |
303 error(loc, "auto can only be used for template function parameters"); | |
304 } | |
0 | 305 } |
73 | 306 argsc.pop(); |
0 | 307 } |
135 | 308 |
309 if (wildreturn && !wildparams) | |
310 error(loc, "inout on return means inout must be on a parameter as well for %s", toChars()); | |
311 if (wildsubparams && wildparams) | |
312 error(loc, "inout must be all or none on top level for %s", toChars()); | |
313 | |
0 | 314 if (tf.next) |
315 tf.deco = tf.merge().deco; | |
316 | |
317 if (tf.inuse) | |
318 { error(loc, "recursive type"); | |
319 tf.inuse = 0; | |
320 return terror; | |
321 } | |
322 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
323 if (tf.isproperty && (tf.varargs || Parameter.dim(tf.parameters) > 1)) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
324 error(loc, "properties can only have zero or one parameter"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
325 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
326 if (tf.varargs == 1 && tf.linkage != LINK.LINKd && Parameter.dim(tf.parameters) == 0) |
0 | 327 error(loc, "variadic functions with non-D linkage must have at least one parameter"); |
328 | |
329 /* Don't return merge(), because arg identifiers and default args | |
330 * can be different | |
331 * even though the types match | |
332 */ | |
333 return tf; | |
334 } | |
335 | |
72 | 336 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 337 { |
338 ubyte mc; | |
339 | |
340 //printf("TypeFunction.toDecoBuffer() this = %p %s\n", this, toChars()); | |
341 //static int nest; if (++nest == 50) *(char*)0=0; | |
342 if (inuse) | |
343 { | |
344 inuse = 2; // flag error to caller | |
345 return; | |
346 } | |
347 inuse++; | |
135 | 348 MODtoDecoBuffer(buf, mod); |
0 | 349 switch (linkage) |
350 { | |
351 case LINK.LINKd: mc = 'F'; break; | |
352 case LINK.LINKc: mc = 'U'; break; | |
353 case LINK.LINKwindows: mc = 'W'; break; | |
354 case LINK.LINKpascal: mc = 'V'; break; | |
355 case LINK.LINKcpp: mc = 'R'; break; | |
356 } | |
357 buf.writeByte(mc); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
358 if (ispure || isnothrow || isproperty || isref || trust) |
0 | 359 { |
360 if (ispure) | |
361 buf.writestring("Na"); | |
362 if (isnothrow) | |
363 buf.writestring("Nb"); | |
364 if (isref) | |
365 buf.writestring("Nc"); | |
366 if (isproperty) | |
367 buf.writestring("Nd"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
368 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
369 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
370 case TRUST.TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
371 buf.writestring("Ne"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
372 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
373 case TRUST.TRUSTsafe: |
135 | 374 buf.writestring("Nf"); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
375 break; |
132
c494af1dba80
Fixes for dmd 2.037
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
131
diff
changeset
|
376 default: |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
377 } |
0 | 378 } |
379 // Write argument types | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
380 Parameter.argsToDecoBuffer(buf, parameters); |
0 | 381 //if (buf.data[buf.offset - 1] == '@') halt(); |
382 buf.writeByte('Z' - varargs); // mark end of arg list | |
79 | 383 assert(next); |
0 | 384 next.toDecoBuffer(buf); |
385 inuse--; | |
386 } | |
387 | |
72 | 388 override void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) |
0 | 389 { |
390 //printf("TypeFunction.toCBuffer() this = %p\n", this); | |
391 string p = null; | |
392 | |
393 if (inuse) | |
394 { | |
395 inuse = 2; // flag error to caller | |
396 return; | |
397 } | |
398 inuse++; | |
399 | |
400 /* Use 'storage class' style for attributes | |
401 */ | |
135 | 402 if (mod) |
403 { | |
404 MODtoBuffer(buf, mod); | |
405 buf.writeByte(' '); | |
406 } | |
0 | 407 |
408 if (ispure) | |
409 buf.writestring("pure "); | |
410 if (isnothrow) | |
411 buf.writestring("nothrow "); | |
412 if (isproperty) | |
413 buf.writestring("@property "); | |
414 if (isref) | |
415 buf.writestring("ref "); | |
416 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
417 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
418 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
419 case TRUST.TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
420 buf.writestring("@trusted "); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
421 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
422 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
423 case TRUST.TRUSTsafe: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
424 buf.writestring("@safe "); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
425 break; |
148 | 426 |
427 default: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
428 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
429 |
0 | 430 if (next && (!ident || ident.toHChars2() == ident.toChars())) |
431 next.toCBuffer2(buf, hgs, MODundefined); | |
432 if (hgs.ddoc != 1) | |
433 { | |
434 switch (linkage) | |
435 { | |
436 case LINKd: p = null; break; | |
73 | 437 case LINKc: p = " C"; break; |
438 case LINKwindows: p = " Windows"; break; | |
439 case LINKpascal: p = " Pascal"; break; | |
440 case LINKcpp: p = " C++"; break; | |
0 | 441 default: |
442 assert(0); | |
443 } | |
444 } | |
445 | |
446 if (!hgs.hdrgen && p) | |
447 buf.writestring(p); | |
448 if (ident) | |
449 { | |
450 buf.writeByte(' '); | |
451 buf.writestring(ident.toHChars2()); | |
452 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
453 Parameter.argsToCBuffer(buf, hgs, parameters, varargs); |
0 | 454 inuse--; |
455 } | |
456 | |
72 | 457 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 458 { |
459 //printf("TypeFunction::toCBuffer2() this = %p, ref = %d\n", this, isref); | |
460 string p; | |
461 | |
462 if (inuse) | |
463 { | |
464 inuse = 2; // flag error to caller | |
465 return; | |
466 } | |
467 | |
468 inuse++; | |
469 if (next) | |
470 next.toCBuffer2(buf, hgs, MODundefined); | |
471 | |
472 if (hgs.ddoc != 1) | |
473 { | |
474 switch (linkage) | |
475 { | |
476 case LINKd: p = null; break; | |
477 case LINKc: p = "C "; break; | |
478 case LINKwindows: p = "Windows "; break; | |
479 case LINKpascal: p = "Pascal "; break; | |
480 case LINKcpp: p = "C++ "; break; | |
481 default: assert(0); | |
482 } | |
483 } | |
484 | |
485 if (!hgs.hdrgen && p) | |
486 buf.writestring(p); | |
487 buf.writestring(" function"); | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
488 Parameter.argsToCBuffer(buf, hgs, parameters, varargs); |
0 | 489 |
490 /* Use postfix style for attributes | |
491 */ | |
492 if (mod != this.mod) | |
493 { | |
494 modToBuffer(buf); | |
495 } | |
496 | |
497 if (ispure) | |
498 buf.writestring(" pure"); | |
499 if (isnothrow) | |
500 buf.writestring(" nothrow"); | |
501 if (isproperty) | |
502 buf.writestring(" @property"); | |
503 if (isref) | |
504 buf.writestring(" ref"); | |
505 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
506 switch (trust) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
507 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
508 case TRUSTtrusted: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
509 buf.writestring(" @trusted"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
510 break; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
511 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
512 case TRUSTsafe: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
513 buf.writestring(" @safe"); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
514 break; |
143 | 515 |
516 default: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
517 } |
0 | 518 inuse--; |
519 } | |
520 | |
72 | 521 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 522 { |
123 | 523 //printf("TypeFunction.deduceType()\n"); |
524 //printf("\tthis = %d, ", ty); print(); | |
525 //printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
526 | |
527 // Extra check that function characteristics must match | |
528 if (tparam && tparam.ty == Tfunction) | |
529 { | |
530 TypeFunction tp = cast(TypeFunction)tparam; | |
531 if (varargs != tp.varargs || | |
532 linkage != tp.linkage) | |
533 return MATCHnomatch; | |
534 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
535 size_t nfargs = Parameter.dim(this.parameters); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
536 size_t nfparams = Parameter.dim(tp.parameters); |
123 | 537 |
538 /* See if tuple match | |
539 */ | |
540 if (nfparams > 0 && nfargs >= nfparams - 1) | |
541 { | |
542 /* See if 'A' of the template parameter matches 'A' | |
543 * of the type of the last function parameter. | |
544 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
545 auto fparam = Parameter.getNth(tp.parameters, nfparams - 1); |
123 | 546 assert(fparam); |
547 assert(fparam.type); | |
548 if (fparam.type.ty != Tident) | |
549 goto L1; | |
550 TypeIdentifier tid = cast(TypeIdentifier)fparam.type; | |
551 if (tid.idents.dim) | |
552 goto L1; | |
553 | |
554 /* Look through parameters to find tuple matching tid.ident | |
555 */ | |
556 size_t tupi = 0; | |
557 for (; 1; tupi++) | |
558 { | |
559 if (tupi == parameters.dim) | |
560 goto L1; | |
561 TemplateParameter t = parameters[tupi]; | |
562 TemplateTupleParameter tup = t.isTemplateTupleParameter(); | |
563 if (tup && tup.ident.equals(tid.ident)) | |
564 break; | |
565 } | |
566 | |
567 /* The types of the function arguments [nfparams - 1 .. nfargs] | |
568 * now form the tuple argument. | |
569 */ | |
570 int tuple_dim = nfargs - (nfparams - 1); | |
571 | |
572 /* See if existing tuple, and whether it matches or not | |
573 */ | |
574 Object o = dedtypes[tupi]; | |
575 if (o) | |
576 { | |
577 // Existing deduced argument must be a tuple, and must match | |
578 Tuple t = isTuple(o); | |
579 if (!t || t.objects.dim != tuple_dim) | |
580 return MATCHnomatch; | |
581 for (size_t i = 0; i < tuple_dim; i++) | |
582 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
583 auto arg = Parameter.getNth(this.parameters, nfparams - 1 + i); |
123 | 584 if (!arg.type.equals(t.objects[i])) |
585 return MATCHnomatch; | |
586 } | |
587 } | |
588 else | |
589 { // Create new tuple | |
590 Tuple t = new Tuple(); | |
591 t.objects.setDim(tuple_dim); | |
592 for (size_t i = 0; i < tuple_dim; i++) | |
593 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
594 auto arg = Parameter.getNth(this.parameters, nfparams - 1 + i); |
123 | 595 t.objects[i] = arg.type; |
596 } | |
597 dedtypes[tupi] = t; | |
598 } | |
599 nfparams--; // don't consider the last parameter for type deduction | |
600 goto L2; | |
601 } | |
602 | |
603 L1: | |
604 if (nfargs != nfparams) | |
605 return MATCHnomatch; | |
606 L2: | |
607 for (size_t i = 0; i < nfparams; i++) | |
608 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
609 auto a = Parameter.getNth(this.parameters, i); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
610 auto ap = Parameter.getNth(tp.parameters, i); |
123 | 611 if (a.storageClass != ap.storageClass || |
612 !a.type.deduceType(sc, ap.type, parameters, dedtypes)) | |
613 return MATCHnomatch; | |
614 } | |
615 } | |
616 return Type.deduceType(sc, tparam, parameters, dedtypes); | |
0 | 617 } |
618 | |
72 | 619 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 620 { |
129 | 621 return new TypeInfoFunctionDeclaration(this); |
0 | 622 } |
623 | |
72 | 624 override Type reliesOnTident() |
0 | 625 { |
135 | 626 size_t dim = Parameter.dim(parameters); |
627 for (size_t i = 0; i < dim; i++) | |
628 { | |
629 auto fparam = Parameter.getNth(parameters, i); | |
630 Type t = fparam.type.reliesOnTident(); | |
631 if (t) | |
632 return t; | |
633 } | |
634 return next ? next.reliesOnTident() : null; | |
0 | 635 } |
636 | |
637 version (CPP_MANGLE) { | |
638 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
639 { | |
640 assert(false); | |
641 } | |
642 } | |
643 | |
644 /*************************** | |
645 * Examine function signature for parameter p and see if | |
646 * p can 'escape' the scope of the function. | |
647 */ | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
648 bool parameterEscapes(Parameter p) |
0 | 649 { |
650 /* Scope parameters do not escape. | |
651 * Allow 'lazy' to imply 'scope' - | |
652 * lazy parameters can be passed along | |
653 * as lazy parameters to the next function, but that isn't | |
654 * escaping. | |
655 */ | |
656 if (p.storageClass & (STC.STCscope | STC.STClazy)) | |
657 return false; | |
658 | |
659 if (ispure) | |
660 { /* With pure functions, we need only be concerned if p escapes | |
661 * via any return statement. | |
662 */ | |
663 Type tret = nextOf().toBasetype(); | |
664 if (!isref && !tret.hasPointers()) | |
665 { /* The result has no references, so p could not be escaping | |
666 * that way. | |
667 */ | |
668 return false; | |
669 } | |
670 } | |
671 | |
672 /* Assume it escapes in the absence of better information. | |
673 */ | |
674 return true; | |
675 } | |
676 | |
677 /******************************** | |
678 * 'args' are being matched to function 'this' | |
679 * Determine match level. | |
680 * Returns: | |
681 * MATCHxxxx | |
682 */ | |
683 MATCH callMatch(Expression ethis, Expressions args) | |
684 { | |
685 //printf("TypeFunction.callMatch() %s\n", toChars()); | |
686 MATCH match = MATCH.MATCHexact; // assume exact match | |
135 | 687 bool exactwildmatch = false; |
688 bool wildmatch = false; | |
0 | 689 |
690 if (ethis) | |
691 { | |
692 Type t = ethis.type; | |
693 if (t.toBasetype().ty == TY.Tpointer) | |
694 t = t.toBasetype().nextOf(); // change struct* to struct | |
695 | |
696 if (t.mod != mod) | |
697 { | |
135 | 698 if (MODimplicitConv(t.mod, mod)) |
0 | 699 match = MATCH.MATCHconst; |
700 else | |
701 return MATCH.MATCHnomatch; | |
702 } | |
703 } | |
704 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
705 size_t nparams = Parameter.dim(parameters); |
0 | 706 size_t nargs = args ? args.dim : 0; |
707 if (nparams == nargs) { | |
708 ; | |
709 } else if (nargs > nparams) | |
710 { | |
711 if (varargs == 0) | |
712 goto Nomatch; // too many args; no match | |
713 match = MATCH.MATCHconvert; // match ... with a "conversion" match level | |
714 } | |
715 | |
716 for (size_t u = 0; u < nparams; u++) | |
717 { | |
718 MATCH m; | |
719 Expression arg; | |
720 | |
721 // BUG: what about out and ref? | |
722 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
723 auto p = Parameter.getNth(parameters, u); |
0 | 724 assert(p); |
725 if (u >= nargs) | |
726 { | |
727 if (p.defaultArg) | |
728 continue; | |
729 if (varargs == 2 && u + 1 == nparams) | |
730 goto L1; | |
731 goto Nomatch; // not enough arguments | |
732 } | |
733 | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
96
diff
changeset
|
734 arg = cast(Expression)args[u]; |
0 | 735 assert(arg); |
96 | 736 // writef("arg: %s, type: %s\n", arg.toChars(), arg.type.toChars()); |
737 | |
0 | 738 |
739 // Non-lvalues do not match ref or out parameters | |
96 | 740 if (p.storageClass & (STC.STCref | STC.STCout)) |
741 { | |
742 if (!arg.isLvalue()) | |
743 goto Nomatch; | |
744 } | |
745 | |
746 if (p.storageClass & STCref) | |
747 { | |
135 | 748 /* Don't allow static arrays to be passed to mutable references |
96 | 749 * to static arrays if the argument cannot be modified. |
750 */ | |
751 Type targb = arg.type.toBasetype(); | |
752 Type tparb = p.type.toBasetype(); | |
753 //writef("%s\n", targb.toChars()); | |
754 //writef("%s\n", tparb.toChars()); | |
755 if (targb.nextOf() && tparb.ty == Tsarray && | |
135 | 756 !MODimplicitConv(targb.nextOf().mod, tparb.nextOf().mod)) |
96 | 757 goto Nomatch; |
758 } | |
0 | 759 |
760 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) | |
761 m = MATCH.MATCHconvert; | |
762 else | |
135 | 763 { |
0 | 764 m = arg.implicitConvTo(p.type); |
135 | 765 if (p.type.isWild()) |
766 { | |
767 if (m == MATCHnomatch) | |
768 { | |
769 m = arg.implicitConvTo(p.type.constOf()); | |
770 if (m == MATCHnomatch) | |
771 m = arg.implicitConvTo(p.type.sharedConstOf()); | |
772 if (m != MATCHnomatch) | |
773 wildmatch = true; // mod matched to wild | |
774 } | |
775 else | |
776 exactwildmatch = true; // wild matched to wild | |
777 | |
778 /* If both are allowed, then there could be more than one | |
779 * binding of mod to wild, leaving a gaping type hole. | |
780 */ | |
781 if (wildmatch && exactwildmatch) | |
782 m = MATCHnomatch; | |
783 } | |
784 } | |
785 | |
0 | 786 //printf("\tm = %d\n", m); |
787 if (m == MATCH.MATCHnomatch) // if no match | |
788 { | |
789 L1: | |
790 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
791 { | |
792 Type tb = p.type.toBasetype(); | |
793 TypeSArray tsa; | |
794 long sz; | |
795 | |
796 switch (tb.ty) | |
797 { | |
798 case TY.Tsarray: | |
799 tsa = cast(TypeSArray)tb; | |
800 sz = tsa.dim.toInteger(); | |
801 if (sz != nargs - u) | |
802 goto Nomatch; | |
803 case TY.Tarray: | |
804 { | |
805 TypeArray ta = cast(TypeArray)tb; | |
806 for (; u < nargs; u++) | |
807 { | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
96
diff
changeset
|
808 arg = cast(Expression)args[u]; |
0 | 809 assert(arg); |
810 static if (true) { | |
811 /* If lazy array of delegates, | |
812 * convert arg(s) to delegate(s) | |
813 */ | |
814 Type tret = p.isLazyArray(); | |
815 if (tret) | |
816 { | |
817 if (ta.next.equals(arg.type)) | |
818 { | |
819 m = MATCH.MATCHexact; | |
820 } | |
821 else | |
822 { | |
823 m = arg.implicitConvTo(tret); | |
824 if (m == MATCH.MATCHnomatch) | |
825 { | |
826 if (tret.toBasetype().ty == TY.Tvoid) | |
827 m = MATCH.MATCHconvert; | |
828 } | |
829 } | |
830 } | |
831 else | |
832 m = arg.implicitConvTo(ta.next); | |
833 } else { | |
834 m = arg.implicitConvTo(ta.next); | |
835 } | |
836 if (m == MATCH.MATCHnomatch) | |
837 goto Nomatch; | |
838 | |
839 if (m < match) | |
840 match = m; | |
841 } | |
842 goto Ldone; | |
843 } | |
844 | |
845 case TY.Tclass: | |
846 // Should see if there's a constructor match? | |
847 // Or just leave it ambiguous? | |
848 goto Ldone; | |
849 | |
850 default: | |
851 goto Nomatch; | |
852 } | |
853 } | |
854 | |
855 goto Nomatch; | |
856 } | |
857 | |
858 if (m < match) | |
859 match = m; // pick worst match | |
860 } | |
861 | |
862 Ldone: | |
863 //printf("match = %d\n", match); | |
864 return match; | |
865 | |
866 Nomatch: | |
867 //printf("no match\n"); | |
868 return MATCH.MATCHnomatch; | |
869 } | |
870 | |
96 | 871 override type* toCtype() |
0 | 872 { |
873 if (ctype) { | |
874 return ctype; | |
875 } | |
876 | |
877 type* t; | |
878 if (true) | |
879 { | |
880 param_t* paramtypes; | |
881 tym_t tyf; | |
882 type* tp; | |
883 | |
884 paramtypes = null; | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
885 size_t nparams = Parameter.dim(parameters); |
0 | 886 for (size_t i = 0; i < nparams; i++) |
887 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
888 auto arg = Parameter.getNth(parameters, i); |
0 | 889 tp = arg.type.toCtype(); |
890 if (arg.storageClass & (STC.STCout | STC.STCref)) | |
891 { | |
892 // C doesn't have reference types, so it's really a pointer | |
893 // to the parameter type | |
894 tp = type_allocn(TYM.TYref, tp); | |
895 } | |
896 param_append_type(¶mtypes,tp); | |
897 } | |
898 tyf = totym(); | |
899 t = type_alloc(tyf); | |
900 t.Tflags |= TF.TFprototype; | |
901 if (varargs != 1) | |
902 t.Tflags |= TF.TFfixed; | |
903 ctype = t; | |
904 t.Tnext = next.toCtype(); | |
905 t.Tnext.Tcount++; | |
906 t.Tparamtypes = paramtypes; | |
907 } | |
908 ctype = t; | |
909 return t; | |
910 } | |
911 | |
912 /*************************** | |
913 * Determine return style of function - whether in registers or | |
914 * through a hidden pointer to the caller's stack. | |
915 */ | |
96 | 916 RET retStyle() |
0 | 917 { |
918 //printf("TypeFunction.retStyle() %s\n", toChars()); | |
95 | 919 version (DMDV2) |
920 { | |
0 | 921 if (isref) |
922 return RET.RETregs; // returns a pointer | |
923 } | |
924 | |
925 Type tn = next.toBasetype(); | |
95 | 926 Type tns = tn; |
927 ulong sz = tn.size(); | |
0 | 928 |
95 | 929 version(SARRAYVALUE) |
930 { | |
931 if (tn.ty == Tsarray) | |
932 { | |
933 do | |
934 { | |
935 tns = tns.nextOf().toBasetype(); | |
936 } while (tns.ty == Tsarray); | |
937 if (tns.ty != Tstruct) | |
938 { | |
939 if (global.params.isLinux && linkage != LINKd) | |
940 {} | |
941 else | |
942 { | |
943 switch (sz) | |
944 { case 1: | |
945 case 2: | |
946 case 4: | |
947 case 8: | |
96 | 948 return RET.RETregs; // return small structs in regs |
949 // (not 3 byte structs!) | |
95 | 950 default: |
951 break; | |
952 } | |
953 } | |
96 | 954 return RET.RETstack; |
95 | 955 } |
956 } | |
957 } | |
958 if (tns.ty == TY.Tstruct) | |
0 | 959 { |
960 StructDeclaration sd = (cast(TypeStruct)tn).sym; | |
961 if (global.params.isLinux && linkage != LINK.LINKd) { | |
962 ; | |
963 } | |
95 | 964 ///version (DMDV2) { // TODO: |
965 else if (sd.dtor || sd.cpctor) | |
966 { | |
0 | 967 } |
968 ///} | |
969 else | |
970 { | |
95 | 971 switch (sz) |
0 | 972 { |
973 case 1: | |
974 case 2: | |
975 case 4: | |
976 case 8: | |
977 return RET.RETregs; // return small structs in regs | |
978 // (not 3 byte structs!) | |
979 default: | |
980 break; | |
981 } | |
982 } | |
983 return RET.RETstack; | |
984 } | |
985 else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && | |
986 linkage == LINK.LINKc && | |
987 tn.iscomplex()) | |
988 { | |
989 if (tn.ty == TY.Tcomplex32) | |
990 return RET.RETregs; // in EDX:EAX, not ST1:ST0 | |
991 else | |
992 return RET.RETstack; | |
993 } | |
994 else | |
995 return RET.RETregs; | |
996 } | |
997 | |
72 | 998 override TYM totym() |
0 | 999 { |
1000 TYM tyf; | |
1001 | |
1002 //printf("TypeFunction.totym(), linkage = %d\n", linkage); | |
1003 switch (linkage) | |
1004 { | |
1005 case LINK.LINKwindows: | |
1006 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnsfunc; | |
1007 break; | |
1008 | |
1009 case LINK.LINKpascal: | |
1010 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnpfunc; | |
1011 break; | |
1012 | |
1013 case LINK.LINKc: | |
1014 tyf = TYM.TYnfunc; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1015 version (POSIX) {///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 1016 if (retStyle() == RET.RETstack) |
1017 tyf = TYM.TYhfunc; | |
1018 } | |
1019 break; | |
1020 | |
1021 case LINK.LINKd: | |
1022 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYjfunc; | |
1023 break; | |
1024 | |
1025 case LINK.LINKcpp: | |
1026 tyf = TYM.TYnfunc; | |
1027 break; | |
1028 | |
1029 default: | |
1030 writef("linkage = %d\n", linkage); | |
1031 assert(0); | |
1032 } | |
1033 version (DMDV2) { | |
1034 if (isnothrow) | |
1035 tyf |= mTY.mTYnothrow; | |
1036 } | |
1037 return tyf; | |
1038 } | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
1039 } |