Mercurial > projects > ddmd
annotate dmd/TypeFunction.d @ 96:acd69f84627e
further work
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 02:12:15 +0200 |
parents | ae5b11064a9a |
children | 3482c73a991b |
rev | line source |
---|---|
0 | 1 module dmd.TypeFunction; |
2 | |
3 import dmd.TypeNext; | |
4 import dmd.TypeSArray; | |
5 import dmd.TypeArray; | |
6 import dmd.ArrayTypes; | |
7 import dmd.LINK; | |
8 import dmd.StructDeclaration; | |
9 import dmd.TypeStruct; | |
10 import dmd.Global; | |
11 import dmd.STC; | |
12 import dmd.MOD; | |
73 | 13 import dmd.PROT; |
0 | 14 import dmd.Type; |
15 import dmd.Loc; | |
16 import dmd.Scope; | |
17 import dmd.Identifier; | |
18 import dmd.OutBuffer; | |
19 import dmd.HdrGenState; | |
20 import dmd.CppMangleState; | |
21 import dmd.TypeInfoDeclaration; | |
22 import dmd.MATCH; | |
23 import dmd.Argument; | |
24 import dmd.Expression; | |
25 import dmd.RET; | |
26 import dmd.TY; | |
27 import dmd.Util; | |
28 | |
29 import dmd.backend.TYPE; | |
30 import dmd.backend.PARAM; | |
31 import dmd.backend.Util; | |
32 import dmd.backend.TYM; | |
33 import dmd.backend.TF; | |
34 import dmd.backend.mTY; | |
35 | |
36 import core.stdc.stdlib; | |
37 import core.stdc.string; | |
38 | |
39 class TypeFunction : TypeNext | |
40 { | |
41 // .next is the return type | |
42 | |
43 Arguments parameters; // function parameters | |
44 int varargs; // 1: T t, ...) style for variable number of arguments | |
45 // 2: T t ...) style for variable number of arguments | |
46 bool isnothrow; // true: nothrow | |
47 bool ispure; // true: pure | |
48 bool isproperty; // can be called without parentheses | |
49 bool isref; // true: returns a reference | |
50 LINK linkage; // calling convention | |
51 | |
52 int inuse; | |
53 | |
54 this(Arguments parameters, Type treturn, int varargs, LINK linkage) | |
55 { | |
56 super(TY.Tfunction, treturn); | |
57 | |
58 //if (!treturn) *(char*)0=0; | |
59 // assert(treturn); | |
60 assert(0 <= varargs && varargs <= 2); | |
61 this.parameters = parameters; | |
62 this.varargs = varargs; | |
63 this.linkage = linkage; | |
64 } | |
65 | |
72 | 66 override Type syntaxCopy() |
0 | 67 { |
68 Type treturn = next ? next.syntaxCopy() : null; | |
69 Arguments params = Argument.arraySyntaxCopy(parameters); | |
70 TypeFunction t = new TypeFunction(params, treturn, varargs, linkage); | |
71 t.mod = mod; | |
72 t.isnothrow = isnothrow; | |
73 t.ispure = ispure; | |
74 t.isproperty = isproperty; | |
75 t.isref = isref; | |
76 | |
77 return t; | |
78 } | |
79 | |
80 version (DumbClone) { | |
81 } else { | |
82 final TypeFunction cloneTo(TypeFunction t) | |
83 { | |
84 super.cloneTo(t); | |
85 | |
86 // these 3 should be set by ctor | |
87 assert(t.parameters is null); | |
88 assert(t.varargs == varargs); | |
89 assert(t.linkage == linkage); | |
90 | |
91 t.isnothrow = isnothrow; | |
92 t.ispure = ispure; | |
93 t.isproperty = isproperty; | |
94 t.isref = isref; | |
95 t.inuse = inuse; | |
96 | |
97 if (parameters) | |
98 { | |
99 t.parameters = parameters.copy(); | |
100 for (size_t i = 0; i < parameters.dim; i++) | |
101 { | |
102 Argument arg = cast(Argument)parameters.data[i]; | |
103 Argument cpy = arg.clone(); | |
104 t.parameters.data[i] = cast(void*)cpy; | |
105 } | |
106 } | |
107 | |
108 return t; | |
109 } | |
110 | |
111 TypeFunction clone() | |
112 { | |
113 assert(this.classinfo == TypeFunction.classinfo); | |
114 return cloneTo(new TypeFunction(null, next, varargs, linkage)); | |
115 } | |
116 } | |
72 | 117 override Type semantic(Loc loc, Scope sc) |
0 | 118 { |
119 if (deco) // if semantic() already run | |
120 { | |
121 //printf("already done\n"); | |
122 return this; | |
123 } | |
124 //printf("TypeFunction.semantic() this = %p\n", this); | |
125 //printf("TypeFunction.semantic() %s, sc.stc = %x\n", toChars(), sc.stc); | |
126 | |
127 /* Copy in order to not mess up original. | |
128 * This can produce redundant copies if inferring return type, | |
129 * as semantic() will get called again on this. | |
130 */ | |
131 | |
132 TypeFunction tf = cast(TypeFunction)clone(); | |
133 | |
134 if (sc.stc & STC.STCpure) | |
135 tf.ispure = true; | |
136 if (sc.stc & STC.STCnothrow) | |
137 tf.isnothrow = true; | |
138 if (sc.stc & STC.STCref) | |
139 tf.isref = true; | |
140 | |
141 tf.linkage = sc.linkage; | |
142 if (tf.next) | |
143 { | |
144 tf.next = tf.next.semantic(loc,sc); | |
96 | 145 version(SARRAYVALUE) {} else |
146 { | |
0 | 147 if (tf.next.toBasetype().ty == TY.Tsarray) |
148 { error(loc, "functions cannot return static array %s", tf.next.toChars()); | |
149 tf.next = Type.terror; | |
150 } | |
96 | 151 } |
0 | 152 if (tf.next.toBasetype().ty == TY.Tfunction) |
153 { error(loc, "functions cannot return a function"); | |
154 tf.next = Type.terror; | |
155 } | |
156 if (tf.next.toBasetype().ty == TY.Ttuple) | |
157 { error(loc, "functions cannot return a tuple"); | |
158 tf.next = Type.terror; | |
159 } | |
160 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) | |
161 error(loc, "functions cannot return scope %s", tf.next.toChars()); | |
162 } | |
163 | |
164 if (tf.parameters) | |
73 | 165 { |
166 /* Create a scope for evaluating the default arguments for the parameters | |
167 */ | |
168 Scope argsc = sc.push(); | |
169 argsc.stc = STCundefined; // don't inherit storage class | |
170 argsc.protection = PROT.PROTpublic; | |
171 | |
172 size_t dim = Argument.dim(tf.parameters); | |
0 | 173 |
174 for (size_t i = 0; i < dim; i++) | |
175 { Argument arg = Argument.getNth(tf.parameters, i); | |
176 | |
177 tf.inuse++; | |
73 | 178 arg.type = arg.type.semantic(loc, argsc); |
0 | 179 if (tf.inuse == 1) tf.inuse--; |
180 | |
181 arg.type = arg.type.addStorageClass(arg.storageClass); | |
182 | |
183 if (arg.storageClass & (STC.STCauto | STC.STCalias | STC.STCstatic)) | |
184 { | |
185 if (!arg.type) | |
186 continue; | |
187 } | |
188 | |
189 Type t = arg.type.toBasetype(); | |
190 | |
191 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) | |
192 { | |
96 | 193 //if (t.ty == TY.Tsarray) |
194 //error(loc, "cannot have out or ref parameter of type %s", t.toChars()); | |
195 if (arg.storageClass & STC.STCout && arg.type.mod & (STCconst | STCimmutable)) | |
196 error(loc, "cannot have const or immutabl out parameter of type %s", t.toChars()); | |
0 | 197 } |
198 if (!(arg.storageClass & STC.STClazy) && t.ty == TY.Tvoid) | |
199 error(loc, "cannot have parameter of type %s", arg.type.toChars()); | |
200 | |
201 if (arg.defaultArg) | |
202 { | |
73 | 203 arg.defaultArg = arg.defaultArg.semantic(argsc); |
204 arg.defaultArg = resolveProperties(argsc, arg.defaultArg); | |
205 arg.defaultArg = arg.defaultArg.implicitCastTo(argsc, arg.type); | |
0 | 206 } |
207 | |
208 /* If arg turns out to be a tuple, the number of parameters may | |
209 * change. | |
210 */ | |
211 if (t.ty == TY.Ttuple) | |
212 { dim = Argument.dim(tf.parameters); | |
213 i--; | |
214 } | |
215 } | |
73 | 216 argsc.pop(); |
0 | 217 } |
218 if (tf.next) | |
219 tf.deco = tf.merge().deco; | |
220 | |
221 if (tf.inuse) | |
222 { error(loc, "recursive type"); | |
223 tf.inuse = 0; | |
224 return terror; | |
225 } | |
226 | |
227 if (tf.varargs == 1 && tf.linkage != LINK.LINKd && Argument.dim(tf.parameters) == 0) | |
228 error(loc, "variadic functions with non-D linkage must have at least one parameter"); | |
229 | |
230 /* Don't return merge(), because arg identifiers and default args | |
231 * can be different | |
232 * even though the types match | |
233 */ | |
234 return tf; | |
235 } | |
236 | |
72 | 237 override void toDecoBuffer(OutBuffer buf, int flag) |
0 | 238 { |
239 ubyte mc; | |
240 | |
241 //printf("TypeFunction.toDecoBuffer() this = %p %s\n", this, toChars()); | |
242 //static int nest; if (++nest == 50) *(char*)0=0; | |
243 if (inuse) | |
244 { | |
245 inuse = 2; // flag error to caller | |
246 return; | |
247 } | |
248 inuse++; | |
249 static if (true) { | |
250 if (mod & MOD.MODshared) | |
251 buf.writeByte('O'); | |
252 if (mod & MOD.MODconst) | |
253 buf.writeByte('x'); | |
254 else if (mod & MOD.MODinvariant) | |
255 buf.writeByte('y'); | |
256 } | |
257 switch (linkage) | |
258 { | |
259 case LINK.LINKd: mc = 'F'; break; | |
260 case LINK.LINKc: mc = 'U'; break; | |
261 case LINK.LINKwindows: mc = 'W'; break; | |
262 case LINK.LINKpascal: mc = 'V'; break; | |
263 case LINK.LINKcpp: mc = 'R'; break; | |
264 } | |
265 buf.writeByte(mc); | |
266 if (ispure || isnothrow || isproperty || isref) | |
267 { | |
268 if (ispure) | |
269 buf.writestring("Na"); | |
270 if (isnothrow) | |
271 buf.writestring("Nb"); | |
272 if (isref) | |
273 buf.writestring("Nc"); | |
274 if (isproperty) | |
275 buf.writestring("Nd"); | |
276 } | |
277 // Write argument types | |
278 Argument.argsToDecoBuffer(buf, parameters); | |
279 //if (buf.data[buf.offset - 1] == '@') halt(); | |
280 buf.writeByte('Z' - varargs); // mark end of arg list | |
79 | 281 assert(next); |
0 | 282 next.toDecoBuffer(buf); |
283 inuse--; | |
284 } | |
285 | |
72 | 286 override void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) |
0 | 287 { |
288 //printf("TypeFunction.toCBuffer() this = %p\n", this); | |
289 string p = null; | |
290 | |
291 if (inuse) | |
292 { | |
293 inuse = 2; // flag error to caller | |
294 return; | |
295 } | |
296 inuse++; | |
297 | |
298 /* Use 'storage class' style for attributes | |
299 */ | |
300 if (mod & MODconst) | |
301 buf.writestring("const "); | |
302 if (mod & MODinvariant) | |
303 buf.writestring("immutable "); | |
304 if (mod & MODshared) | |
305 buf.writestring("shared "); | |
306 | |
307 if (ispure) | |
308 buf.writestring("pure "); | |
309 if (isnothrow) | |
310 buf.writestring("nothrow "); | |
311 if (isproperty) | |
312 buf.writestring("@property "); | |
313 if (isref) | |
314 buf.writestring("ref "); | |
315 | |
316 if (next && (!ident || ident.toHChars2() == ident.toChars())) | |
317 next.toCBuffer2(buf, hgs, MODundefined); | |
318 if (hgs.ddoc != 1) | |
319 { | |
320 switch (linkage) | |
321 { | |
322 case LINKd: p = null; break; | |
73 | 323 case LINKc: p = " C"; break; |
324 case LINKwindows: p = " Windows"; break; | |
325 case LINKpascal: p = " Pascal"; break; | |
326 case LINKcpp: p = " C++"; break; | |
0 | 327 default: |
328 assert(0); | |
329 } | |
330 } | |
331 | |
332 if (!hgs.hdrgen && p) | |
333 buf.writestring(p); | |
334 if (ident) | |
335 { | |
336 buf.writeByte(' '); | |
337 buf.writestring(ident.toHChars2()); | |
338 } | |
339 Argument.argsToCBuffer(buf, hgs, parameters, varargs); | |
340 inuse--; | |
341 } | |
342 | |
72 | 343 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 344 { |
345 //printf("TypeFunction::toCBuffer2() this = %p, ref = %d\n", this, isref); | |
346 string p; | |
347 | |
348 if (inuse) | |
349 { | |
350 inuse = 2; // flag error to caller | |
351 return; | |
352 } | |
353 | |
354 inuse++; | |
355 if (next) | |
356 next.toCBuffer2(buf, hgs, MODundefined); | |
357 | |
358 if (hgs.ddoc != 1) | |
359 { | |
360 switch (linkage) | |
361 { | |
362 case LINKd: p = null; break; | |
363 case LINKc: p = "C "; break; | |
364 case LINKwindows: p = "Windows "; break; | |
365 case LINKpascal: p = "Pascal "; break; | |
366 case LINKcpp: p = "C++ "; break; | |
367 default: assert(0); | |
368 } | |
369 } | |
370 | |
371 if (!hgs.hdrgen && p) | |
372 buf.writestring(p); | |
373 buf.writestring(" function"); | |
374 Argument.argsToCBuffer(buf, hgs, parameters, varargs); | |
375 | |
376 /* Use postfix style for attributes | |
377 */ | |
378 if (mod != this.mod) | |
379 { | |
380 modToBuffer(buf); | |
381 } | |
382 | |
383 if (ispure) | |
384 buf.writestring(" pure"); | |
385 if (isnothrow) | |
386 buf.writestring(" nothrow"); | |
387 if (isproperty) | |
388 buf.writestring(" @property"); | |
389 if (isref) | |
390 buf.writestring(" ref"); | |
391 | |
392 inuse--; | |
393 } | |
394 | |
72 | 395 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) |
0 | 396 { |
397 assert(false); | |
398 } | |
399 | |
72 | 400 override TypeInfoDeclaration getTypeInfoDeclaration() |
0 | 401 { |
402 assert(false); | |
403 } | |
404 | |
72 | 405 override Type reliesOnTident() |
0 | 406 { |
407 if (parameters) | |
408 { | |
409 for (size_t i = 0; i < parameters.dim; i++) | |
410 { | |
411 Argument arg = cast(Argument)parameters.data[i]; | |
412 Type t = arg.type.reliesOnTident(); | |
413 if (t) | |
414 return t; | |
415 } | |
416 } | |
417 return next.reliesOnTident(); | |
418 } | |
419 | |
420 version (CPP_MANGLE) { | |
421 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
422 { | |
423 assert(false); | |
424 } | |
425 } | |
426 | |
427 /*************************** | |
428 * Examine function signature for parameter p and see if | |
429 * p can 'escape' the scope of the function. | |
430 */ | |
431 bool parameterEscapes(Argument p) | |
432 { | |
433 /* Scope parameters do not escape. | |
434 * Allow 'lazy' to imply 'scope' - | |
435 * lazy parameters can be passed along | |
436 * as lazy parameters to the next function, but that isn't | |
437 * escaping. | |
438 */ | |
439 if (p.storageClass & (STC.STCscope | STC.STClazy)) | |
440 return false; | |
441 | |
442 if (ispure) | |
443 { /* With pure functions, we need only be concerned if p escapes | |
444 * via any return statement. | |
445 */ | |
446 Type tret = nextOf().toBasetype(); | |
447 if (!isref && !tret.hasPointers()) | |
448 { /* The result has no references, so p could not be escaping | |
449 * that way. | |
450 */ | |
451 return false; | |
452 } | |
453 } | |
454 | |
455 /* Assume it escapes in the absence of better information. | |
456 */ | |
457 return true; | |
458 } | |
459 | |
460 /******************************** | |
461 * 'args' are being matched to function 'this' | |
462 * Determine match level. | |
463 * Returns: | |
464 * MATCHxxxx | |
465 */ | |
466 MATCH callMatch(Expression ethis, Expressions args) | |
467 { | |
468 //printf("TypeFunction.callMatch() %s\n", toChars()); | |
469 MATCH match = MATCH.MATCHexact; // assume exact match | |
470 | |
471 if (ethis) | |
472 { | |
473 Type t = ethis.type; | |
474 if (t.toBasetype().ty == TY.Tpointer) | |
475 t = t.toBasetype().nextOf(); // change struct* to struct | |
476 | |
477 if (t.mod != mod) | |
478 { | |
479 if (mod == MOD.MODconst) | |
480 match = MATCH.MATCHconst; | |
481 else | |
482 return MATCH.MATCHnomatch; | |
483 } | |
484 } | |
485 | |
486 size_t nparams = Argument.dim(parameters); | |
487 size_t nargs = args ? args.dim : 0; | |
488 if (nparams == nargs) { | |
489 ; | |
490 } else if (nargs > nparams) | |
491 { | |
492 if (varargs == 0) | |
493 goto Nomatch; // too many args; no match | |
494 match = MATCH.MATCHconvert; // match ... with a "conversion" match level | |
495 } | |
496 | |
497 for (size_t u = 0; u < nparams; u++) | |
498 { | |
499 MATCH m; | |
500 Expression arg; | |
501 | |
502 // BUG: what about out and ref? | |
503 | |
504 Argument p = Argument.getNth(parameters, u); | |
505 assert(p); | |
506 if (u >= nargs) | |
507 { | |
508 if (p.defaultArg) | |
509 continue; | |
510 if (varargs == 2 && u + 1 == nparams) | |
511 goto L1; | |
512 goto Nomatch; // not enough arguments | |
513 } | |
514 | |
515 arg = cast(Expression)args.data[u]; | |
516 assert(arg); | |
96 | 517 // writef("arg: %s, type: %s\n", arg.toChars(), arg.type.toChars()); |
518 | |
0 | 519 |
520 // Non-lvalues do not match ref or out parameters | |
96 | 521 if (p.storageClass & (STC.STCref | STC.STCout)) |
522 { | |
523 if (!arg.isLvalue()) | |
524 goto Nomatch; | |
525 } | |
526 | |
527 if (p.storageClass & STCref) | |
528 { | |
529 /* Don't allow static arrays to be passed to mutable refereces | |
530 * to static arrays if the argument cannot be modified. | |
531 */ | |
532 Type targb = arg.type.toBasetype(); | |
533 Type tparb = p.type.toBasetype(); | |
534 //writef("%s\n", targb.toChars()); | |
535 //writef("%s\n", tparb.toChars()); | |
536 if (targb.nextOf() && tparb.ty == Tsarray && | |
537 targb.nextOf().mod != tparb.nextOf().mod && | |
538 !tparb.nextOf().isConst()) | |
539 goto Nomatch; | |
540 } | |
0 | 541 |
542 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) | |
543 m = MATCH.MATCHconvert; | |
544 else | |
545 m = arg.implicitConvTo(p.type); | |
546 //printf("\tm = %d\n", m); | |
547 if (m == MATCH.MATCHnomatch) // if no match | |
548 { | |
549 L1: | |
550 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
551 { | |
552 Type tb = p.type.toBasetype(); | |
553 TypeSArray tsa; | |
554 long sz; | |
555 | |
556 switch (tb.ty) | |
557 { | |
558 case TY.Tsarray: | |
559 tsa = cast(TypeSArray)tb; | |
560 sz = tsa.dim.toInteger(); | |
561 if (sz != nargs - u) | |
562 goto Nomatch; | |
563 case TY.Tarray: | |
564 { | |
565 TypeArray ta = cast(TypeArray)tb; | |
566 for (; u < nargs; u++) | |
567 { | |
568 arg = cast(Expression)args.data[u]; | |
569 assert(arg); | |
570 static if (true) { | |
571 /* If lazy array of delegates, | |
572 * convert arg(s) to delegate(s) | |
573 */ | |
574 Type tret = p.isLazyArray(); | |
575 if (tret) | |
576 { | |
577 if (ta.next.equals(arg.type)) | |
578 { | |
579 m = MATCH.MATCHexact; | |
580 } | |
581 else | |
582 { | |
583 m = arg.implicitConvTo(tret); | |
584 if (m == MATCH.MATCHnomatch) | |
585 { | |
586 if (tret.toBasetype().ty == TY.Tvoid) | |
587 m = MATCH.MATCHconvert; | |
588 } | |
589 } | |
590 } | |
591 else | |
592 m = arg.implicitConvTo(ta.next); | |
593 } else { | |
594 m = arg.implicitConvTo(ta.next); | |
595 } | |
596 if (m == MATCH.MATCHnomatch) | |
597 goto Nomatch; | |
598 | |
599 if (m < match) | |
600 match = m; | |
601 } | |
602 goto Ldone; | |
603 } | |
604 | |
605 case TY.Tclass: | |
606 // Should see if there's a constructor match? | |
607 // Or just leave it ambiguous? | |
608 goto Ldone; | |
609 | |
610 default: | |
611 goto Nomatch; | |
612 } | |
613 } | |
614 | |
615 goto Nomatch; | |
616 } | |
617 | |
618 if (m < match) | |
619 match = m; // pick worst match | |
620 } | |
621 | |
622 Ldone: | |
623 //printf("match = %d\n", match); | |
624 return match; | |
625 | |
626 Nomatch: | |
627 //printf("no match\n"); | |
628 return MATCH.MATCHnomatch; | |
629 } | |
630 | |
96 | 631 override type* toCtype() |
0 | 632 { |
633 if (ctype) { | |
634 return ctype; | |
635 } | |
636 | |
637 type* t; | |
638 if (true) | |
639 { | |
640 param_t* paramtypes; | |
641 tym_t tyf; | |
642 type* tp; | |
643 | |
644 paramtypes = null; | |
645 size_t nparams = Argument.dim(parameters); | |
646 for (size_t i = 0; i < nparams; i++) | |
647 { | |
648 Argument arg = Argument.getNth(parameters, i); | |
649 tp = arg.type.toCtype(); | |
650 if (arg.storageClass & (STC.STCout | STC.STCref)) | |
651 { | |
652 // C doesn't have reference types, so it's really a pointer | |
653 // to the parameter type | |
654 tp = type_allocn(TYM.TYref, tp); | |
655 } | |
656 param_append_type(¶mtypes,tp); | |
657 } | |
658 tyf = totym(); | |
659 t = type_alloc(tyf); | |
660 t.Tflags |= TF.TFprototype; | |
661 if (varargs != 1) | |
662 t.Tflags |= TF.TFfixed; | |
663 ctype = t; | |
664 t.Tnext = next.toCtype(); | |
665 t.Tnext.Tcount++; | |
666 t.Tparamtypes = paramtypes; | |
667 } | |
668 ctype = t; | |
669 return t; | |
670 } | |
671 | |
672 /*************************** | |
673 * Determine return style of function - whether in registers or | |
674 * through a hidden pointer to the caller's stack. | |
675 */ | |
96 | 676 RET retStyle() |
0 | 677 { |
678 //printf("TypeFunction.retStyle() %s\n", toChars()); | |
95 | 679 version (DMDV2) |
680 { | |
0 | 681 if (isref) |
682 return RET.RETregs; // returns a pointer | |
683 } | |
684 | |
685 Type tn = next.toBasetype(); | |
95 | 686 Type tns = tn; |
687 ulong sz = tn.size(); | |
0 | 688 |
95 | 689 version(SARRAYVALUE) |
690 { | |
691 if (tn.ty == Tsarray) | |
692 { | |
693 do | |
694 { | |
695 tns = tns.nextOf().toBasetype(); | |
696 } while (tns.ty == Tsarray); | |
697 if (tns.ty != Tstruct) | |
698 { | |
699 if (global.params.isLinux && linkage != LINKd) | |
700 {} | |
701 else | |
702 { | |
703 switch (sz) | |
704 { case 1: | |
705 case 2: | |
706 case 4: | |
707 case 8: | |
96 | 708 return RET.RETregs; // return small structs in regs |
709 // (not 3 byte structs!) | |
95 | 710 default: |
711 break; | |
712 } | |
713 } | |
96 | 714 return RET.RETstack; |
95 | 715 } |
716 } | |
717 } | |
718 if (tns.ty == TY.Tstruct) | |
0 | 719 { |
720 StructDeclaration sd = (cast(TypeStruct)tn).sym; | |
721 if (global.params.isLinux && linkage != LINK.LINKd) { | |
722 ; | |
723 } | |
95 | 724 ///version (DMDV2) { // TODO: |
725 else if (sd.dtor || sd.cpctor) | |
726 { | |
0 | 727 } |
728 ///} | |
729 else | |
730 { | |
95 | 731 switch (sz) |
0 | 732 { |
733 case 1: | |
734 case 2: | |
735 case 4: | |
736 case 8: | |
737 return RET.RETregs; // return small structs in regs | |
738 // (not 3 byte structs!) | |
739 default: | |
740 break; | |
741 } | |
742 } | |
743 return RET.RETstack; | |
744 } | |
745 else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && | |
746 linkage == LINK.LINKc && | |
747 tn.iscomplex()) | |
748 { | |
749 if (tn.ty == TY.Tcomplex32) | |
750 return RET.RETregs; // in EDX:EAX, not ST1:ST0 | |
751 else | |
752 return RET.RETstack; | |
753 } | |
754 else | |
755 return RET.RETregs; | |
756 } | |
757 | |
72 | 758 override TYM totym() |
0 | 759 { |
760 TYM tyf; | |
761 | |
762 //printf("TypeFunction.totym(), linkage = %d\n", linkage); | |
763 switch (linkage) | |
764 { | |
765 case LINK.LINKwindows: | |
766 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnsfunc; | |
767 break; | |
768 | |
769 case LINK.LINKpascal: | |
770 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnpfunc; | |
771 break; | |
772 | |
773 case LINK.LINKc: | |
774 tyf = TYM.TYnfunc; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
775 version (POSIX) {///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 776 if (retStyle() == RET.RETstack) |
777 tyf = TYM.TYhfunc; | |
778 } | |
779 break; | |
780 | |
781 case LINK.LINKd: | |
782 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYjfunc; | |
783 break; | |
784 | |
785 case LINK.LINKcpp: | |
786 tyf = TYM.TYnfunc; | |
787 break; | |
788 | |
789 default: | |
790 writef("linkage = %d\n", linkage); | |
791 assert(0); | |
792 } | |
793 version (DMDV2) { | |
794 if (isnothrow) | |
795 tyf |= mTY.mTYnothrow; | |
796 } | |
797 return tyf; | |
798 } | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
799 } |